如何在不使用 sudo 的情况下安装 virtualenv?

发布于 2025-01-07 13:31:01 字数 556 浏览 1 评论 0原文

我有 easy_installpip

我的 Linux Mint 12 上出现了很多错误,我刚刚重新安装了它,我想再次从头开始安装所有内容。

这是我遇到的错误之一有。我在那里收到了一个有趣的答案:

停止使用 su 和 sudo 运行 virtualenv。
您需要以普通用户身份运行 virtualenv。
您已经使用 sudo 创建了 virtualenv,这就是您收到这些错误的原因。

那么如何在不使用 sudo 的情况下安装 virtualenv 呢?我可以使用 pipeasy_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 pipor easy_install without using sudo? Or is there another way?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(12

呆° 2025-01-14 13:31:01

此解决方案适用于系统范围内没有可用的 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,

    $ mkdir ~/bin
    $ mkdir -p ~/lib/python2.6
    $ mkdir -p ~/local/lib/python2.6/dist-packages
    $ wget http://peak.telecommunity.com/dist/virtual-python.py
    $ python virtual-python.py --no-site-packages
    $ wget http://peak.telecommunity.com/dist/ez_setup.py
    $ ~/bin/python ez_setup.py
    $ ~/local/bin/easy_install virtualenv
    $ ~/local/bin/virtualenv --no-site-packages thereyouare

可能还有优化的空间。我不喜欢 local 路径。只要 binlib 就很好了。但它确实发挥了作用。

This solution is suitable in cases where no virtualenv is available system wide and you can not become root to install virtualenv. When I set up a debian for python development or deployment I always apt-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

    $ mkdir ~/bin
    $ mkdir -p ~/lib/python2.6
    $ mkdir -p ~/local/lib/python2.6/dist-packages
    $ wget http://peak.telecommunity.com/dist/virtual-python.py
    $ python virtual-python.py --no-site-packages
    $ wget http://peak.telecommunity.com/dist/ez_setup.py
    $ ~/bin/python ez_setup.py
    $ ~/local/bin/easy_install virtualenv
    $ ~/local/bin/virtualenv --no-site-packages thereyouare

There may be room for optimization. I don't like the local path. Just bin and lib would be nice. But it does its job.

玻璃人 2025-01-14 13:31:01

您还可以使用下面的命令,它对我来说没有 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 using export, see this SO answer for more details.

pip install --user virtualenv

一瞬间的火花 2025-01-14 13:31:01

总体思路是全局安装 virtualenv 本身,即 sudo easy_install virtualenvsudo pip install virtualenv,然后创建 本地实际的虚拟环境(“运行 virtualenv”)。

The general idea is to install virtualenv itself globaly, i.e. sudo easy_install virtualenv or sudo pip install virtualenv, but then create the actual virtual environment ("run virtualenv") locally.

水染的天色ゝ 2025-01-14 13:31:01

http://opensourcehacker.com/2012/09/16/recommended-way-for-sudo-free-installation-of-python-software-with-virtualenv/ 建议以下内容:

curl -L -o virtualenv.py https://raw.githubusercontent.com/pypa/virtualenv/master/virtualenv.py
python virtualenv.py vvv-venv
. vvv-venv/bin/activate
pip install vvv

看起来效果不错。它允许我使用 piphttps://github.com/miohtama/vvv >。

如果您得到:

Cannot find sdist setuptools-*.tar.gz
Cannot find sdist pip-*.tar.gz

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:

curl -L -o virtualenv.py https://raw.githubusercontent.com/pypa/virtualenv/master/virtualenv.py
python virtualenv.py vvv-venv
. vvv-venv/bin/activate
pip install vvv

It seems to work well. It lets me install https://github.com/miohtama/vvv with pip.

If you get:

Cannot find sdist setuptools-*.tar.gz
Cannot find sdist pip-*.tar.gz

Try --extra-search-dir after downloading the tarballs at https://github.com/pypa/virtualenv/tree/develop/virtualenv_support

美人如玉 2025-01-14 13:31:01

对我有用:

pip install --target=$HOME/virtualenv/ virtualenv
cd somewhere/
python $HOME/virtualenv/virtualenv.py env
. env/bin/activate

现在我可以pip install任何我想要的东西(除了所有需要的东西)使用 gcc 编译内容并且缺少依赖项,例如 python 开发库和 Python.h)。

This worked for me:

pip install --target=$HOME/virtualenv/ virtualenv
cd somewhere/
python $HOME/virtualenv/virtualenv.py env
. env/bin/activate

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 and Python.h).

一刻暧昧 2025-01-14 13:31:01

基本上这个想法是将 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 to source ~/.profile it if just added)

独自←快乐 2025-01-14 13:31:01

我创建了一个“便携式”virtualenv 版本

wget https://bitbucket.org/techtonik/locally/raw/tip/06.get-virtualenv.py
python 06.get-virtualenv.py

它将具有依赖项的 virtualenv.py 脚本下载到 .locally 子目录中并从那里执行它。完成后,可以将带有 .locally/ 子目录的脚本复制到任何地方。

I've created a "portable" version of virtualenv.

wget https://bitbucket.org/techtonik/locally/raw/tip/06.get-virtualenv.py
python 06.get-virtualenv.py

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.

眼眸 2025-01-14 13:31:01

我解决了为每个用户安装 virtualenv 的问题。

python3 -m pip install --user virtualenv

I solved my problem installing virtualenv for each user.

python3 -m pip install --user virtualenv
凉世弥音 2025-01-14 13:31:01

您可能需要考虑使用 Anaconda。它是一个成熟的 Python 发行版,位于您的主目录中的一个文件夹中。任何时候都不需要 sudo,您可以获得大多数流行的软件包。

$ wget https://.../Anaconda2-2.5.0-Linux-x86_64.sh # check the website for the exact URL, it can change
$ bash Anaconda2-2.5.0-Linux-x86_64.sh
$ conda install virtualenv

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.

$ wget https://.../Anaconda2-2.5.0-Linux-x86_64.sh # check the website for the exact URL, it can change
$ bash Anaconda2-2.5.0-Linux-x86_64.sh
$ conda install virtualenv
追风人 2025-01-14 13:31:01

到目前为止我见过的最简单的方法是安装 Anaconda。
这对你来说可能有点过分了。对我来说,远程服务器上运行的centOS只安装了python2.6。 Anaconda 默认情况下在本地安装所有内容 + 它是 python2.7

curl -O https://repo.continuum.io/archive/Anaconda2-4.2.0-Linux-x86_64.sh

然后

bash Anaconda2-4.2.0-Linux-x86_64.sh

Boom。您已经安装了 numpy 和 pip 等所有软件包。
然后如果你想要 virtualenv,只需输入

pip install 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

curl -O https://repo.continuum.io/archive/Anaconda2-4.2.0-Linux-x86_64.sh

Then

bash Anaconda2-4.2.0-Linux-x86_64.sh

Boom. You have all the packages like numpy and pip installed.
Then if you want virtualenv, just type

pip install virtualenv
美人如玉 2025-01-14 13:31:01
sudo virtualenv -p python myenv1

sudo su
source myenv1/bin/activate


pip install mypackage

这将安装在虚拟环境中

sudo virtualenv -p python myenv1

sudo su
source myenv1/bin/activate


pip install mypackage

this is will install inside virtual environment

溇涏 2025-01-14 13:31:01

缺少 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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文