如何在不使用 sudo 的情况下安装 virtualenv?
我有 easy_install
和 pip
。
我的 Linux Mint 12 上出现了很多错误,我刚刚重新安装了它,我想再次从头开始安装所有内容。
停止使用 su 和 sudo 运行 virtualenv。
您需要以普通用户身份运行 virtualenv。
您已经使用 sudo 创建了 virtualenv,这就是您收到这些错误的原因。
那么如何在不使用 sudo 的情况下安装 virtualenv 呢?我可以使用 pip
或 easy_install
而不使用 sudo
吗?或者还有别的办法吗?
I have easy_install
and pip
.
I had many errors on my Linux Mint 12, I just re-installed it and I want to install everything from scratch again.
This is one of the errors that I had. I received an interesting answer there:
Stop using su and sudo to run virtualenv.
You need to run virtualenv as your normal user.
You have created the virtualenv with sudo which is why you are getting these errors.
So how to install virtualenv
without using sudo
? Can i use pip
or easy_install
without using sudo
? Or is there another way?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(12)
此解决方案适用于系统范围内没有可用的
virtualenv
并且您无法成为 root 来安装virtualenv
的情况。当我设置 debian 进行 python 开发或部署时,我总是 apt-get install python-virtualenv 。拥有它比执行下面指出的引导程序更方便。但如果没有 root 权限,这可能是可行的方法:有一个引导机制可以让您继续前进。
阅读:http://peak.telecommunity.com/DevCenter/EasyInstall#creating -a-virtual-python
本质上,您可以在 unix 环境中的主目录中执行此操作:
鉴于您的 python 版本是 2.6,
可能还有优化的空间。我不喜欢
local
路径。只要bin
和lib
就很好了。但它确实发挥了作用。This solution is suitable in cases where no
virtualenv
is available system wide and you can not become root to installvirtualenv
. When I set up a debian for python development or deployment I alwaysapt-get install python-virtualenv
. It is more convenient to have it around than to do the bootstrap pointed out below. But without root power it may be the the way to go:There is a bootstrap mechanism that should get you going.
Read: http://peak.telecommunity.com/DevCenter/EasyInstall#creating-a-virtual-python
In essence you would do this in your home directory in a unix environment:
Given your python is version 2.6
There may be room for optimization. I don't like the
local
path. Justbin
andlib
would be nice. But it does its job.您还可以使用下面的命令,它对我来说没有
sudo
访问权限。您可能还需要使用
export
修改PYTHONPATH
环境变量,请参阅此答案以获取更多详细信息。pip install --user virtualenv
You can also use the command below, it worked for me without
sudo
access.You may also need to modify your
PYTHONPATH
environment variable usingexport
, see this SO answer for more details.pip install --user virtualenv
总体思路是全局安装
virtualenv
本身,即sudo easy_install virtualenv
或sudo pip install virtualenv
,然后创建 本地实际的虚拟环境(“运行 virtualenv”)。The general idea is to install
virtualenv
itself globaly, i.e.sudo easy_install virtualenv
orsudo pip install virtualenv
, but then create the actual virtual environment ("run virtualenv") locally.http://opensourcehacker.com/2012/09/16/recommended-way-for-sudo-free-installation-of-python-software-with-virtualenv/ 建议以下内容:
看起来效果不错。它允许我使用
pip
https://github.com/miohtama/vvv >。如果您得到:
在 https://github.com/pypa/virtualenv/tree/develop/virtualenv_support
http://opensourcehacker.com/2012/09/16/recommended-way-for-sudo-free-installation-of-python-software-with-virtualenv/ suggests the following:
It seems to work well. It lets me install https://github.com/miohtama/vvv with
pip
.If you get:
Try
--extra-search-dir
after downloading the tarballs at https://github.com/pypa/virtualenv/tree/develop/virtualenv_support这对我有用:
现在我可以
pip install
任何我想要的东西(除了所有需要的东西)使用 gcc 编译内容并且缺少依赖项,例如 python 开发库和 Python.h)。This worked for me:
Now I can
pip install
whatever I want (except for everything that needs to compile stuff with gcc and has missing dependencies such as the python development libraries andPython.h
).基本上这个想法是将 virtualenv (或任何其他 python 包)安装到
${HOME}/.local
中。这是最合适的位置,因为它默认包含在 python 路径中(而不仅仅是 Python)。您可以通过
pip3 install virtualenv --prefix=${HOME}/.local
执行此操作(您可能需要扩展${HOME}
)。确保您的
~/.profile
中有export PATH=${HOME}/.local/bin:${PATH}
(您可能需要source ~/.profile
如果刚刚添加的话)Basically the idea is to install virtualenv (or any other python package) into
${HOME}/.local
. This is the most appropriate location since it is included into python path by default (and not only Python).That you do by
pip3 install virtualenv --prefix=${HOME}/.local
(you may need to expand${HOME}
).Make sure that you have
export PATH=${HOME}/.local/bin:${PATH}
in your~/.profile
(you may need tosource ~/.profile
it if just added)我创建了一个“便携式”virtualenv 版本 。
它将具有依赖项的
virtualenv.py
脚本下载到.locally
子目录中并从那里执行它。完成后,可以将带有 .locally/ 子目录的脚本复制到任何地方。I've created a "portable" version of virtualenv.
It downloads
virtualenv.py
script with dependencies into.locally
subdir and executes it from there. Once that's done, the script with .locally/ subdir can be copied anywhere.我解决了为每个用户安装 virtualenv 的问题。
I solved my problem installing virtualenv for each user.
您可能需要考虑使用 Anaconda。它是一个成熟的 Python 发行版,位于您的主目录中的一个文件夹中。任何时候都不需要 sudo,您可以获得大多数流行的软件包。
You might want to consider using Anaconda. It's a full-fledged Python distribution, that lives in a folder in e.g. your home directory. No
sudo
is necessary at any point and you get most of the popular packages.到目前为止我见过的最简单的方法是安装 Anaconda。
这对你来说可能有点过分了。对我来说,远程服务器上运行的centOS只安装了python2.6。 Anaconda 默认情况下在本地安装所有内容 + 它是 python2.7
然后
Boom。您已经安装了 numpy 和 pip 等所有软件包。
然后如果你想要 virtualenv,只需输入
The easiest way I have seen so far is to install Anaconda.
It may be an overkill for you. For me the centOS running on the remote server had only python2.6 installed. Anaconda by default installs everything locally + it is python2.7
Then
Boom. You have all the packages like numpy and pip installed.
Then if you want virtualenv, just type
这将安装在虚拟环境中
this is will install inside virtual environment
缺少 sudo 是许多共享远程服务器中的常见情况。
事实证明,有一种更简单、更轻量、更安全的解决方案。只需从这里下载官方的“便携式”virtualenv: https://bootstrap.pypa.io/virtualenv.pyz
就是这样!您现在可以随心所欲地运行
python virtualenv.pyz --help
。官方文档:https://virtualenv.pypa.io/en/latest /installation.html#via-zipapp
The lack of sudo is a common situation in many shared remote server.
It turns out, there is a simpler, lightweight, more secure solution. Just download an official "portable" virtualenv from here: https://bootstrap.pypa.io/virtualenv.pyz
And that is it! You can now run
python virtualenv.pyz --help
to your heart's content.Official document: https://virtualenv.pypa.io/en/latest/installation.html#via-zipapp