Reputation: 599
I have just downloaded python 3.6.1 from github and built it in a local dir. Now I am trying to make a virtualenv with that version of python but I keep getting:
Running virtualenv with interpreter /home/giorgio/tools/cpython-3.6.1/python
Using base prefix '/usr/local'
Traceback (most recent call last):
File "/usr/lib/python2.7/site-packages/virtualenv.py", line 2462, in <module>
main()
File "/usr/lib/python2.7/site-packages/virtualenv.py", line 762, in main
symlink=options.symlink,
File "/usr/lib/python2.7/site-packages/virtualenv.py", line 998, in create_environment
install_python(home_dir, lib_dir, inc_dir, bin_dir, site_packages=site_packages, clear=clear, symlink=symlink)
File "/usr/lib/python2.7/site-packages/virtualenv.py", line 1219, in install_python
copy_required_modules(home_dir, symlink)
File "/usr/lib/python2.7/site-packages/virtualenv.py", line 1147, in copy_required_modules
dst_filename = change_prefix(filename, dst_prefix)
File "/usr/lib/python2.7/site-packages/virtualenv.py", line 1111, in change_prefix
assert False, "Filename {} does not start with any of these prefixes: {}".format(filename, prefixes)
AssertionError: Filename /home/giorgio/tools/cpython-3.6.1/Lib/os.py does not start with any of these prefixes: ['/usr/local', '/usr/local']
I don't want to install this version of python globally on the system. Is there another way to make virtualenv work with it?
Upvotes: 5
Views: 5167
Reputation: 1039
I had a similar problem when trying to create an environment after having upgraded to Python 3.9. In my case, I still had the Python3.6 virtualenv packages installed from the OS repo, which created this conflict. The solution was to also upgrade the virtualenv infrastructure to its Python 3.9 equivalent:
sudo apt -y remove virtualenv python3-virtualenv virtualenvwrapper
pip install virtualenv virtualenvwrapper
Upvotes: 0
Reputation: 1919
I ran into this error attempting to use my brew-installed version of Python 3.9.5 to create a new virtual environment on macOS. (mkvirtualenv
with virtualenvwrapper
)
My command format is typically:
mkvirtualenv -p python3 [env-name]
Not sure what caused this to get messed up, but ultimately I got it working again by running:
python3.9 -m venv ~/.virtualenvs/myenvname
This puts the env in your normal spot, and you can still run workon myenvname
Upvotes: 5
Reputation: 439
The right way to achieve this is to set the prefix when you configure the build options to be a local directory and then perform make install
. So if the directory you want to install things at is $HOME/pythons
then in the build directory run:
./configure --prefix="${HOME}/pythons"
make
make install
Upvotes: 2