Install virtualenv with pip3 and it will default to using python3 as the interpreter
sudo apt install python3-pip
pip3 install virtualenv
If all you are looking to do is set your virtual environment to python3 then you would use the command
virtualenv -p /usr/bin/python3.x (name of your environment here)
For PyCcharm to use python3 you have to do it from within PyCharm itself. The remainder of my response is taken directly from https://www.cs.rit.edu/~csci141/Docs/PyCharm-Setup.html.
On the welcome screen, go to the lower right of the window and select
Configure -> Settings (or Preferences) -> Default Project -> Project
Interpreter.
In the settings window, you will now configure the default projects
you make in PyCharm to use Python 3.
When the setting dialog comes up, select the Project Interpreter to
choose the Python 3 interpreter that you just installed.
Turn off the default use of venv for projects. You should see a
settings button (e.g. gear) for adding an interpreter. Instead, choose
the system interpreter to override the venv.
Now select the OK button at the bottom and PyCharm will do the updates
back on the welcome screen.
You will now turn off the style warnings for what's known as "PEP 8",
Python's style enforcement. (We do not use standard Python style in
this course.) You do this by opening the preferences, selecting
"Inspections" under Editor -> CodeStyle, and unchecking the "PEP 8"
violation checkboxes as shown below. You can search for "pep" to find
this more quickly than scrolling.
Finally you can turn off the authorship line in the Editor's Code
Templates for Python by erasing the whole line containing the
author text in the template; you can see the line in the screen below. (You may want to visit the templates later to customize them.)
You can then use the following code to test your settings.
NOTE python3-tk must be installed sudo apt install python3-tk
""" sample.py is a sample python3 program using turtle graphics. """
python import turtle def drawSquare():
"""
drawSquare draws a square with sides of length 100.
"""
turtle.forward(100)
turtle.left(90)
turtle.forward(100)
turtle.left(90)
turtle.forward(100)
turtle.left(90)
turtle.forward(100)
turtle.left(90) def main():
"""
main program draws a square and waits user to hit Enter key.
"""
drawSquare()
print('Close the canvas window to end the program...')
turtle.done() if __name__ == '__main__':
main()
You can first run the code by right-clicking in the code window and
selecting Run sample. If everything is correct, you should see a
separate Python turtle drawing window come up, and the console should
open in the bottom pane of PyCharm.