Virtualenvwrapper creating project in wrong directory?

一曲冷凌霜 提交于 2019-12-04 16:56:47

On VirtualEnvWrapper's documentation, they say "optionally":

WORKON_HOME (Optional)

Add an environment variable WORKON_HOME to specify the path to store environments. By default, this is %USERPROFILE%\Envs.

That %USERPROFILE% part is why you're seeing a directory named Envs created at C:/users/me.

I'm not posting this to act like a know-it-all; this tripped me up too as I just glazed right over it.

I did some research and it turns out in Windows CMD, you can do something like:

set WORKON_HOME=%cd%

where `%cd% is your current directory. You'd think that this would set the environment variable permanently, but no, it doesn't. It's only temporary.

I also tried:

mkvirtualenv -a C:\Django venv

but the path was just ignored and was still created in %USERPROFILE%\Envs.

To set the WORKON_HOME environment variable permanently on your Windows machine, you have to go into the environment variables (search how to get there if you don't know how) and do the following:

After you have set your WORKON_HOME directory, in Windows CMD prompt, you can then do (notice my current path is at C:\Django):

C:\Django>mkvirtualenv venv

This is what will appear on the screen:

Using base prefix 'c:\\python35'
New python executable in C:\Django\venv\Scripts\python.exe
Installing setuptools, pip, wheel...done.

(venv) C:\Django>

When you do mkvirtualenv name it's creating the virtualenv in the current directory you're in in the shell. To create it in the place you want you either need to specify the path or navigate there and create the virtualenv

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!