0

I wanna make python virtual environment.

  • my WSL default python version is 3.8

As I know, two methods are...

  1. `python -m venv .venv'
    .venv is created default python version 3.8.
    It's fine and no problem.

  2. python -version -m venv .venv
    ex. python -3.8 -m venv .venv

$ python -3.11 -m venv .venv
Unknown option: -3
usage: python [option] ... [-c cmd | -m mod | file | -] [arg] ...
Try `python -h' for more information.

what is wrong above command? Thank you in advance.

(Refer to above paragraph.)

I wanna use venv command. (not virtualenv)

1
  • You need to install Python 3.11 first, and not to mention the -3 is not a flag that you can pass into python hence the error message. You might be thinking of using something like pyenv instead to find/manage specific Python versions? Commented Jan 16, 2023 at 3:19

1 Answer 1

2

python version depends on version venv module called from. for example one way would be:

%python --version
Python 3.8.3

%python -m venv venvpy3.8 

if activate the env with the default version which is 3.8.3 here.

to find all python versions in my system, following script helps:

from os import listdir
from os.path import isfile, join
import re
python_re=r"^python\d"
path=os.environ["PATH"]
probable_python_versions=[]
for e_path in path.split(":"):
    python_versions=[os.path.join(e_path,file_folder) for file_folder in listdir(e_path) if isfile(join(e_path, file_folder)) and (re.match(r"^python\d\.\d+$",file_folder)) ]
    probable_python_versions.extend(python_versions)
print(probable_python_versions)

so it provides a list as

['/opt/anaconda3/bin/python3.8',
 '/Library/Frameworks/Python.framework/Versions/3.8/bin/python3.8',
 '/usr/local/bin/python3.8',
 '/usr/local/bin/python3.11',
 '/usr/local/bin/python3.9',
 '/usr/bin/python2.7']

now a need is for virtual env with 3.11, a way would be % /usr/local/bin/python3.11 -m venv venvpy3.11 and can activate and this env will have python 3.11

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.