Sourabh Nilakhe
Sourabh Nilakhe

Reputation: 33

Creating virtualenv with python3

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

Upvotes: 1

Views: 1585

Answers (2)

vu le
vu le

Reputation: 361

Improve upon answer of @ParthS007 (Wanted to add a comment to the existing answer but couldn't due to not enough reputation):

  1. Corrected the virtual environment name to be the common used one venv so it's easier for beginners like me to use/understand in conjunction with other tutorials.
  2. 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 venv

To activate env

source env/bin/activate

To deactivate env

deactivate

To remove env

rm -rf venv

Upvotes: 0

ParthS007
ParthS007

Reputation: 2689

For making a virtual environment with Python 3

Use this for making env

python3 -m venv env

To activate env

source env/bin/activate

Upvotes: 9

Related Questions