I generally use python2.7 for projects.
For one project, I need to use python 3.5+.
I installed python3 on Mac.
Also installed virtualenv using pip3.
Now when I run the command
virtualenv -p python3 test
I get the following error:
Running virtualenv with interpreter /usr/bin/python3
Already using interpreter /Library/Developer/CommandLineTools/usr/bin/python3
Using base prefix '/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.7'
New python executable in /Users/sourabh/virtualenvs/test/bin/python3
Also creating executable in /Users/sourabh/virtualenvs/test/bin/python
Traceback (most recent call last):
File "/Library/Python/3.7/site-packages/virtualenv.py", line 2632, in <module>
main()
File "/Library/Python/3.7/site-packages/virtualenv.py", line 870, in main
symlink=options.symlink,
File "/Library/Python/3.7/site-packages/virtualenv.py", line 1156, in create_environment
install_python(home_dir, lib_dir, inc_dir, bin_dir, site_packages=site_packages, clear=clear, symlink=symlink)
File "/Library/Python/3.7/site-packages/virtualenv.py", line 1621, in install_python
shutil.copy(original_python, py_executable)
File "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.7/lib/python3.7/shutil.py", line 245, in copy
copyfile(src, dst, follow_symlinks=follow_symlinks)
File "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.7/lib/python3.7/shutil.py", line 103, in copyfile
if _samefile(src, dst):
File "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.7/lib/python3.7/shutil.py", line 88, in _samefile
return os.path.samefile(src, dst)
File "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.7/lib/python3.7/genericpath.py", line 96, in samefile
s1 = os.stat(f1)
TypeError: stat: path should be string, bytes, os.PathLike or integer, not NoneType
-
I think for mac it is "virtualenv yourenvname -p python3.6"Trollsors– Trollsors2019年10月11日 07:33:22 +00:00Commented Oct 11, 2019 at 7:33
-
1Check version of pip3 and update, then update virtualenv. This is an old issue that should be resolvedKent Martin– Kent Martin2019年10月11日 07:37:27 +00:00Commented Oct 11, 2019 at 7:37
-
1Also, to avoid headaches, I would recommend you to take a look at pyenv. It helps you manage several versions of Python on the same system. You can for example make Python 3.x by default instead of the antique 2.7 of macOS.frankie567– frankie5672019年10月11日 07:37:46 +00:00Commented Oct 11, 2019 at 7:37
-
I confirm what @KentMartin said. Upgrading virtualenv works.ubik– ubik2021年01月06日 13:38:32 +00:00Commented Jan 6, 2021 at 13:38
2 Answers 2
For making a virtual environment with Python 3
Use this for making env
python3 -m venv env
To activate env
source env/bin/activate
Comments
Improve upon answer of @ParthS007 (Wanted to add a comment to the existing answer but couldn't due to not enough reputation):
- Corrected the virtual environment name to be the common used one
venvso it's easier for beginners like me to use/understand in conjunction with other tutorials. - Added how to deactivate and remove virtual environment too.
For making a virtual environment with Python 3
Use this for making env
python3 -m venv venvTo activate env
source env/bin/activate
To deactivate env
deactivate
To remove env
rm -rf venv