简体   繁体   English

如果要使用virtualenv,应该在哪里找到Python文件?

[英]Where should I locate my Python file if I want to use virtualenv?

I have a virtual environment and I do not know where should I save my Python file ? 我有一个虚拟环境,不知道该将Python文件保存在哪里? it only works when I run it in /home/jojo/Enviroment/venv1 can I save it in other place ? 它只能在/home/jojo/Enviroment/venv1运行时才能工作,可以将其保存在其他位置吗? Especially when I want to use PyCharm thank you 特别是当我想使用PyCharm时,谢谢

virtualenv and your code base can very well be in different locations. virtualenv和您的代码库可能位于不同的位置。 I prefer things this way. 我喜欢这种方式。 Here are sample commands that I use. 这是我使用的示例命令。

Step 1 : Activate the virtualenv. 步骤1 :激活virtualenv。

[mayank@demo /dev]$ source /usr/local/pyenv3.4/bin/activate
(pyenv3.4)[mayank@demo dev]$ 

Notice the prefix "(pyenv3.4)" that indicates that virtualenv is now activated. 注意前缀“(pyenv3.4)”,它指示virtualenv现在已激活。

Step 2 : Ensure that python executable in virtualenv is indeed pointed by "python" 第2步 :确保virtualenv中的python可执行文件确实由“ python”指向

(pyenv3.4)[mayank@demo dev]$ which python 
/usr/local/pyenv3.4/bin/python

Notice that python is indeed pointing to the one in virtualenv directory. 注意,python确实指向virtualenv目录中的那个。

Step 3 : Create a file elsewhere and execute it 步骤3 :在其他位置创建文件并执行

echo "import sys; print(sys.executable)" > /tmp/print_python_exe.py
python /tmp/print_python_exe.py

Edit: As suggested by Paul, one might choose to keep the virtualenv directory inside the app directory. 编辑:如Paul所建议,可能选择将virtualenv目录保留在app目录内。 This style of structuring projects is also suggested here: http://docs.python-guide.org/en/latest/dev/virtualenvs/#basic-usage 此处也建议采用这种结构的项目结构形式: http : //docs.python-guide.org/en/latest/dev/virtualenvs/#basic-usage

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM