简体   繁体   English

虚拟环境包装器 CentOS7

[英]virtualenvwrapper CentOS7

I tried to setup virtualenv with virtualenvwrapper on CentOS 7 using pip and I get a UnicodeDecode Error.我尝试使用 pip 在 CentOS 7 上使用 virtualenvwrapper 设置 virtualenv,但出现 UnicodeDecode 错误。

Exact Steps:确切步骤:

  • Install CentOS7安装 CentOS7
  • Install pip via get-pip.py通过 get-pip.py 安装 pip
  • sudo pip install virtualenv须藤 pip 安装 virtualenv
  • sudo pip install virtualenvwrapper须藤 pip 安装 virtualenvwrapper
  • export WORKON_HOME=$HOME/.virtualenvs导出 WORKON_HOME=$HOME/.virtualenvs
  • source /usr/local/bin/virtualenvwrapper.sh源/usr/local/bin/virtualenvwrapper.sh

when I run mkvirtualenv test I get当我运行mkvirtualenv test我得到

 New python executable in test/bin/python
 Traceback (most recent call last):
 File "<string>", line 1, in <module>
 UnicodeDecodeError: 'ascii' codec can't decode byte 0xc2 in position 11 ordinal not in range(128)
 ERROR: The executable Blog/bin/python is not functioning
 ERROR: It thinks sys.prefix is u'/home/blaw/\xac./virtualenvs' (should be u'/home/blaw/\xac./virtualenvs/Blog')
 ERROR: virtualenv is not compatible with this system or executable

What am I doing wrong?我究竟做错了什么?

echo 'export WORKON_HOME=$HOME/.virtualenvs' >> ~/.bashrc

echo 'source /usr/bin/virtualenvwrapper.sh' >> ~/.bashrc

source ~/.bashrc

mkvirtualenv test

That should be OK.那应该没问题。

i found two strange lines in your steps list:我在您的步骤列表中发现了两行奇怪的行:

  • export WORKON_HOME=$HOME/.virtualenvs导出 WORKON_HOME=$HOME/.virtualenvs
  • source /usr/local/bin/virtualenvwrapper.sh源/usr/local/bin/virtualenvwrapper.sh

Does that mean that you just executed these commands in your cli?这是否意味着您只是在 cli 中执行了这些命令?

Actually, what you have to do, is include these two lines in your .bashrc file, as the answer of sxx implies.实际上,正如sxx的答案所暗示的那样,您必须做的是将这两行包含在您的 .bashrc 文件中。

So, instead of echoing and append those lines, i edited the .bashrc file with vim (you can also use nano if its easier to you).因此,我没有回显和附加这些行,而是使用 vim 编辑了 .bashrc 文件(如果对您来说更容易,您也可以使用 nano)。 And manually add it at the end of the file.并手动添加到文件末尾。

I'm not sure if its better, but i added the tilde symbol ( ~ ) insted of the $HOME variable:我不确定它是否更好,但我在 $HOME 变量中添加了波浪号( ~ ):

export WORKON_HOME=~/.virtualenvs
source /usr/bin/virtualenvwrapper.sh

If you read carefully, in centos7 the virtualenvwrapper.sh script, is located in the directory /usr/bin/ and NOT within /usr/local/bin as you wrote.如果您仔细阅读,在 centos7 中, virtualenvwrapper.sh脚本位于/usr/bin/目录中,而不是您编写的/usr/local/bin中。

Once you added those lines, saved your modified .bashrc file, en exit the vim or nano editor, you can create now the .virtualenvs directory, and then source the .bashrc file (kind of restarting your bash cli, with the changes that you just have made):一旦你添加这些线路,保存修改后.bashrc文件,连接退出VIM或纳米编辑器,你现在可以创建.virtualenvs目录,然后.bashrc文件(一种重新启动的bash命令行,用改变你刚刚制作):

mkdir ~/.virtualenvs
source ~/.bashrc

If everything is ok, you should see that the virtualenvwrapper will create some scripts within the .virtualenvs directory.如果一切正常,您应该会看到 virtualenvwrapper 将在.virtualenvs目录中创建一些脚本。

To test if your virtualenvwrapper is working, you can just create a test-environment:要测试您的 virtualenvwrapper 是否正常工作,您只需创建一个测试环境:

mkvirtualenv test

The command to exit the environment is deactivate .退出环境的命令是deactivate You can remove your test environment with rmvirtualenv test .您可以使用rmvirtualenv test删除您的测试环境。 I hope it helps.我希望它有帮助。

When I source ~/.bashrc, it displays no such file. 当我找到〜/ .bashrc的源代码时,它不显示任何此类文件。 I have found virtualenvwrapper.sh in /usr/bin, but it not exists. 我在/ usr / bin中找到virtualenvwrapper.sh,但它不存在。

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

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