Virtualenvwrapper creating project in wrong direct

2020-07-27 20:26发布

I'm extremely new to Python and virtualenv, so I apologize if this is an obvious question. I've got a C drive and a D drive on my pc running windows 10. I have the python and scripts path set to the proper location on the D drive.

In console, i did a pip install virtualenv and pip install virtualenvwrapper-win. After that i navigated to a folder on my D drive where i want my projects. When I ran mkvirtualenv HelloWorld, it seems to have created the virtualenvironment in my C:/users/me folder. Additionally, the virtual env was not activated by default and I was not moved to the correct directory in my console.

How can I ensure that mkvirtualenv creates new virtual environments in the correct folder on my D drive? And what am I doing wrong to not activate virtual env after creation?

2条回答
smile是对你的礼貌
2楼-- · 2020-07-27 21:04

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:

Make VirtualEnv on Windows

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>
查看更多
兄弟一词,经得起流年.
3楼-- · 2020-07-27 21:21

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

查看更多
登录 后发表回答