我很困惑,我应该把我的virtualenvs放在哪里.
在我的第一个django项目中,我使用命令创建了项目
django-admin.py startproject djangoproject
Run Code Online (Sandbox Code Playgroud)
然后我进入djangoproject目录并运行命令
virtualenv env
Run Code Online (Sandbox Code Playgroud)
它创建了与内部djangoproject目录相同级别的虚拟环境目录.
这是为这个特定项目创建virtualenv的错误位置吗?
我得到的印象是,大多数人将所有的virtualenvs保存在一个完全不同的目录中,例如~/virtualenvs,然后使用virtualenvwrapper在它们之间来回切换.
有没有正确的方法来做到这一点?
遵循Doug Hellman的virtualenvwrapper帖子后,我仍然无法启动测试环境.
[mpenning@tsunami ~]$ mkvirtualenv test
-bash: mkvirtualenv: command not found
[mpenning@tsunami ~]$
Run Code Online (Sandbox Code Playgroud)
应该注意的是,我使用WORKON_HOME的不是我的$HOME.我试图寻找/usr/local/bin/virtualenvwrapper.sh如图所示的virtualenvwrapper安装文件,但它不存在.
我正在运行CentOS 6和python 2.6.6,如果这很重要的话.
# File: ~/.bash_profile
# ...
export WORKON_HOME="/opt/virtual_env/"
source "/opt/virtual_env/bin/virtualenvwrapper_bashrc"
Run Code Online (Sandbox Code Playgroud) 我有一个python程序,我想安装到我的virtualenv - 它是一个zip包,我需要解压缩,然后运行一个setup.py程序 - 但我的问题是更多的关于如何将这些解压缩的文件放入我的virtualenv所以包安装到virtualenv的site-packages文件夹中?
我也可以从我的virtualenv内部安装使用pip install <package name>,但由于某种原因,PIP下载的包已过期.
那么 - 有人能告诉我手动安装软件包的几个简单步骤吗?
到目前为止,我已经有了加载Virtualenv的基本命令:
-bash-3.2$ source ~/.bashrc
-bash-3.2$ workon test
(test)-bash-3.2$ //Now I'm working on my virtualenv, but where do I go after this??
Run Code Online (Sandbox Code Playgroud)
那么 - 解压缩python包/程序的位置是否重要 - 或者我应该在解压缩之前首先登录virtualenv?在我加载了virtualenv并且我在内部使用'workon test'命令之后,我安装的任何python包,无论我找到它的目录,都将自己安装到正确的virtualenv的site-packages文件夹中?
选项1是将python程序解压缩到/ home/username/tmp - 然后登录到我的virtualenv,导航到该文件夹并运行setup.py程序 - 假设virtualenv将所有相关文件传输到它自己的site-packages文件夹.
或者方案2是将文件直接解压缩到站点包中,然后从那里运行(登录到virtualenv后)等等
感谢您帮助Python clutz!
我正在运行Mac OS 10.6.8.并希望除了python 2.6还安装python 2.7并在新的virtualenv中使用python 2.7.我执行了以下步骤:
我下载了python 2.7并安装了它:
http://www.python.org/ftp/python/2.7.3/python-2.7.3-macosx10.6.dmg
Run Code Online (Sandbox Code Playgroud)
然后我运行命令使用python2.7设置一个新的virtualenv:
mkvirtualenv --python=python2.7 mynewenv
Run Code Online (Sandbox Code Playgroud)
我的.bash_profile如下所示:
# needed for virtualenvwrapper
export WORKON_HOME=$HOME/.virtualenvs
export VIRTUALENVWRAPPER_PYTHON=/usr/local/bin/python
export VIRTUALENVWRAPPER_VIRTUALENV=/usr/local/bin/virtualenv
source /usr/local/bin/virtualenvwrapper.sh
# Setting PATH for Python 2.7
# The orginal version is saved in .bash_profile.pysave
PATH="/Library/Frameworks/Python.framework/Versions/2.7/bin:${PATH}"
export PATH
Run Code Online (Sandbox Code Playgroud)
现在,当我打开控制台时,我收到以下错误消息.
ImportError: No module named virtualenvwrapper.hook_loader
virtualenvwrapper.sh: There was a problem running the initialization hooks. If Python could not import the module virtualenvwrapper.hook_loader, check that virtualenv has been installed for VIRTUALENVWRAPPER_PYTHON=/usr/local/bin/python and that PATH is set properly. …Run Code Online (Sandbox Code Playgroud) 我想设置一个crontab来运行Python脚本.
说脚本是这样的:
#!/usr/bin/python
print "hello world"
Run Code Online (Sandbox Code Playgroud)
有没有办法为这个Python脚本指定一个virtualenv来运行?在shell中,我只是这样做:
~$ workon myenv
Run Code Online (Sandbox Code Playgroud)
我可以在crontab中做些什么来激活virtualenv吗?
注意:我正在使用virtualenvwrapper.
在激活虚拟环境之前:
$ pip install lxml
Requirement already satisfied (use --upgrade to upgrade): lxml in /usr/lib/python2.7/dist-packages
Cleaning up...
Run Code Online (Sandbox Code Playgroud)
激活虚拟环境后:
(test-env)$ pip install lxml
force/build/lxml/src/lxml/includes/etree_defs.h:9:31: fatal error:
libxml/xmlversion.h: No such file or directory
compilation terminated.
error: command 'gcc' failed with exit status 1
----------------------------------------
Command /home/chaz/dev/envs/test-with-system-python-force/bin/python2
.7 -c "import setuptools;__file__='/home/chaz/dev/envs/test-with-
system-python-force/build/lxml/setup.py';exec(compile(open(__file__).
read().replace('\r\n', '\n'), __file__, 'exec'))" install --record
/tmp/pip-bJ6Q_B-record/install-record.txt --single-version-externally
-managed --install-headers /home/chaz/dev/envs/test-env/include/site/python2.7 failed with error code 1 in
/home/chaz/dev/envs/test-env/build/lxml
Storing complete log in /home/chaz/.pip/pip.log
Run Code Online (Sandbox Code Playgroud) tow-81-235:Projects pessimisticoptimism$ mkvirtualenv development
-bash: mkvirtualenv: command not found
tow-81-235:Projects pessimisticoptimism$ sudo pip install virtualenvwrapper
Password:
Requirement already satisfied (use --upgrade to upgrade): virtualenvwrapper in /Library/Python/2.7/site-packages
Requirement already satisfied (use --upgrade to upgrade): virtualenv in /Library/Python/2.7/site-packages (from virtualenvwrapper)
Requirement already satisfied (use --upgrade to upgrade): virtualenv-clone in /Library/Python/2.7/site-packages (from virtualenvwrapper)
Cleaning up...
tow-81-235:Projects pessimisticoptimism$ mkvirtualenv development
-bash: mkvirtualenv: command not found
Run Code Online (Sandbox Code Playgroud)
为什么我收到此错误?我virtualenv和virtualenvwrapper安装.我想用mkvirtualenv和workon.我觉得奇怪的是virtualenv它有效,但事实virtualenvwrapper并非如此.
所以,再一次,我做了一个很好的python程序,让我的生活变得更轻松,节省了大量的时间.当然,这涉及到virtualenv,由virtualenvwrapper的mkvirtualenv功能.该项目有一个requirements.txt文件,其中包含一些必需的库(请求也是:D),如果没有这些库,程序将无法运行.
我试图添加一个bin/run-app可执行的shell脚本,它将在我的路径中(实际上是符号链接).现在,在这个脚本里面,我需要切换到virtualenv才能运行这个程序.所以我把它放进去了
#!/bin/bash
# cd into the project directory
workon "$(cat .venv)"
python main.py
Run Code Online (Sandbox Code Playgroud)
一个文件.venv包含virtualenv名称.但是当我运行这个脚本时,我会收到workon: command not found错误.
当然,我在我的bashrc中有virtualenvwrapper.sh,但它似乎在这个shell脚本中不可用.
那么,我如何在这里访问那些virtualenvwrapper函数呢?或者我这样做是错误的吗?你如何启动你的python工具,每个工具都有自己的virtualenv!?
我最近擦了我的Mac并重新安装了OSX El Capitan公测版3.我安装了pip sudo easy_install pip并安装了virtualenv sudo pip install virtualenv并且没有任何问题.
现在,当我尝试时sudo pip install virtualenvwrapper,我得到以下内容:
Users-Air:~ User$ sudo pip install virtualenvwrapper
The directory '/Users/User/Library/Caches/pip/http' or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
The directory '/Users/User/Library/Caches/pip/http' or its parent directory is not owned by the current user and the …Run Code Online (Sandbox Code Playgroud) 关于类似问题的许多其他线程,但没有我能找到与我的情况完全相同的情况.所以,这里是:
我做的事情:
sudo easy_install pipsudo pip install virtualenvsudo pip install virtualenvwrapper当前状态:
.bash_profile中
export PATH=/usr/local/bin:$PATH
export PIP_DOWNLOAD_CACHE=$HOME/.pip/cache
export WORKON_HOME=$HOME/.virtualenvs
export PIP_VIRTUALENV_BASE=$WORKON_HOME
export VIRTUALENVWRAPPER_PYTHON=/usr/bin/python
Run Code Online (Sandbox Code Playgroud)运行mkvirtualenv test结果:
New python executable in trunk/bin/python
Installing setuptools, pip...done.
/usr/bin/python: No module named virtualenvwrapper
Run Code Online (Sandbox Code Playgroud)手动检查'/ usr/local/bin'表示virtualenvwrapper.sh存在
/usr/bin/python我尝试过的:
任何帮助实现这项工作将非常感激.