How to install virtualenv without using sudo?

2019-01-08 08:31发布

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?

9条回答
时光不老,我们不散
2楼-- · 2019-01-08 09:26

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).

查看更多
小情绪 Triste *
3楼-- · 2019-01-08 09:28

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)

查看更多
一夜七次
4楼-- · 2019-01-08 09:34

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.

查看更多
登录 后发表回答