mdval
mdval

Reputation: 11

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

Upvotes: 0

Views: 4160

Answers (2)

Paul Tuckett
Paul Tuckett

Reputation: 1073

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!

Upvotes: 1

phd
phd

Reputation: 94473

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 .

Upvotes: 2

Related Questions