Virtualenvwrapper 在错误的目录中创建项目? [英] Virtualenvwrapper creating project in wrong directory?

查看:23
本文介绍了Virtualenvwrapper 在错误的目录中创建项目?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对 Python 和 virtualenv 非常陌生,所以如果这是一个明显的问题,我深表歉意.我在运行 Windows 10 的电脑上有一个 C 驱动器和一个 D 驱动器.我将 python 和脚本路径设置为 D 驱动器上的正确位置.

在控制台中,我执行了 pip install virtualenv 和 pip install virtualenvwrapper-win.之后,我导航到我想要我的项目的 D 驱动器上的文件夹.当我运行 mkvirtualenv HelloWorld 时,它似乎在我的 C:/users/me 文件夹中创建了虚拟环境.此外,默认情况下未激活虚拟环境,并且我没有移动到控制台中的正确目录.

如何确保 mkvirtualenv 在我的 D 驱动器上的正确文件夹中创建新的虚拟环境?创建后不激活虚拟环境我做错了什么?

解决方案

关于

设置好 WORKON_HOME 目录后,在 Windows CMD 提示符下,您就可以执行(注意我当前的路径在 C:\Django):

C:\Django>mkvirtualenv venv

这是将出现在屏幕上的内容:

使用基本前缀 'c:\\python35'C:\Django\venv\Scripts\python.exe 中的新 python 可执行文件安装 setuptools、pip、wheel...完成.(venv) C:\Django>

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?

解决方案

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>

这篇关于Virtualenvwrapper 在错误的目录中创建项目?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆