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)

Kiran Deep
  • 83
  • 7
dEitY719
  • 1
  • 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](https://stackoverflow.com/questions/58138493/finding-versions-of-python-that-are-available-for-pyenv-install) instead to find/manage specific Python versions? – metatoaster Jan 16 '23 at 03:19

1 Answers1

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

simpleApp
  • 2,885
  • 2
  • 10
  • 19