'how to make mkvirtualenv work with current directory?
I'm trying to use mkvirtualenv . to create a virtualenv in the current directory, but with no success:
~/repos/foo$ mkvirtualenv .
created virtual environment CPython3.9.5.final.0-64 in 284ms
creator CPython3Posix(dest=/Users/mdval/.virtualenvs, clear=False, no_vcs_ignore=False, global=False)
seeder FromAppData(download=False, pip=bundle, setuptools=bundle, wheel=bundle, via=copy, app_data_dir=/Users/mdval/Library/Application Support/virtualenv)
added seed packages: pip==21.2.3, setuptools==57.4.0, wheel==0.37.0
activators BashActivator,CShellActivator,FishActivator,PowerShellActivator,PythonActivator
ERROR: Environment 'foo' does not exist. Create it with 'mkvirtualenv foo'.
However, using mkvirtualenv foo works. Can someone help me, please?
Here's my .zshrc config:
export WORKON_HOME=$HOME/.virtualenvs
export PROJECT_HOME=$HOME/repos
export VIRTUALENVWRAPPER_PYTHON=/usr/local/bin/python3
source /usr/local/bin/virtualenvwrapper.sh
Solution 1:[1]
virtualenvwrapper is intended to manage all you virtual environments. To do that it stores all virtual envs in one place — under $WORKON_HOME. That is, mkvirtualenv foo creates a virtual env in $HOME/.virtualenvs/foo/.
If you want to create a virtual env in a different directory that means you want to create a virtual env that is not under control of virtualenvwrapper. Sure, no problem, just create a virtual env using virtualenv:
virtualenv .
Solution 2:[2]
The command you're looking for is: mkvirtualenv env_name -a ./. This will create a virtualenv in your current directory.
So when you do workon env_name it will automagically take you to the directory you specified.
For example: If I am in my ~/Repos/project/backend and run mkvirtualenv project_env -a ./ it doesn't matter where I'm at when I run workon project_env it will take me to ~/Repos/project/backend.
Hope this helps!
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | phd |
| Solution 2 | Paul Tuckett |
