code

pip 및 virtualenv를 시스템 전체에 설치하는 공식 "선호"방법은 무엇입니까?

codestyles 2020. 9. 14. 20:57
반응형

pip 및 virtualenv를 시스템 전체에 설치하는 공식 "선호"방법은 무엇입니까?


사람들이 가장 자주 추천하는 것 같습니다.

$ sudo apt-get install python-setuptools
$ sudo easy_install pip
$ sudo pip install virtualenv

또는 http://www.pip-installer.org/en/latest/installing.html 에서 얻은 것입니다 .

$ curl -O https://github.com/pypa/virtualenv/raw/master/virtualenv.py
$ python virtualenv.py my_new_env
$ . my_new_env/bin/activate
(my_new_env)$ pip install ...

아니면 완전히 다른 걸까요?


최신 Python (2.7.9 이상)을 설치할 수있는 경우 Pip이 번들로 제공됩니다. 참조 : https://docs.python.org/2.7//installing/index.html
그렇지 않은 경우 :
업데이트 (출시 정보에서) :

v1.5.1부터 pip는 get-pip.py를 실행하기 전에 setuptools가 필요하지 않습니다. 또한 setuptools (또는 배포)가 아직 설치되지 않은 경우 get-pip.py가 setuptools를 설치합니다.

이제 일반 실행 :

curl --silent --show-error --retry 5 https://bootstrap.pypa.io/get-pip.py | sudo python

공식 설치 지침은 다음과 같습니다. http://pip.readthedocs.org/en/latest/installing.html#install-pip

2013 년 7 월 25 일 수정 :
setuptools 설치 URL이 변경되었습니다.

2014 년 2 월 10 일 수정 :
setuptools 설치 제거 (@Ciantic에게 감사)

2014 년 6 월 26 일 수정 :
URL을 다시 업데이트했습니다 (@LarsH에게 감사드립니다)

2015 년 3 월 1 일 수정 :
Pip은 이제 Python과 함께 번들로 제공됩니다.


http://www.pip-installer.org/en/latest/installing.html 은이 질문에 대한 정식 답변입니다.

특히, 시스템 전체 지침은 다음과 같습니다.

$ curl -O http://python-distribute.org/distribute_setup.py
$ python distribute_setup.py
$ curl -O https://raw.github.com/pypa/pip/master/contrib/get-pip.py
$ python get-pip.py

질문에 인용 된 섹션은 virtualenv시스템 전체가 아닌 지침입니다. easy_install지침은 이상 주변에 있었다,하지만 더 이상 그런 식으로 할 필요가 없습니다.


이 답변은 Twitter의 @webology에서 나왔습니다.

$ sudo apt-get install python-setuptools
$ sudo easy_install pip
$ sudo pip install --upgrade pip virtualenv virtualenvwrapper

내가 추가 한 메모 :

  • On Mac/Windows (and Linux if the apt repo is outdated) you'd replace the first step with downloading setuptools from http://pypi.python.org/pypi/setuptools
  • On Windows you'd have to omit virtualenvwrapper from the last step and install it manually somehow. I don't know if there's a way to do this without Cygwin, but I hope so.

On Ubuntu 12.04 I've had good luck just using the package manager:

sudo apt-get install python-pip virtualenvwrapper

There is no preferred method - everything depends on your needs. Often you need to have different Python interpreters on the system for whatever reason. In this case you need to install the stuff individually for each interpreter. Apart from that: I prefer installing stuff myself instead of depending of pre-packaged stuff sometimes causing issues - but that's only one possible opionion.


There really isn't a single "answer" to this question, but there are definitely some helpful concepts that can help you to come to a decision.

The first question that needs to be answered in your use case is "Do I want to use the system Python?" If you want to use the Python distributed with your operating system, then using the apt-get install method may be just fine. Depending on the operating system distribution method though, you still have to ask some more questions, such as "Do I want to install multiple versions of this package?" If the answer is yes, then it is probably not a good idea to use something like apt. Dpkg pretty much will just untar an archive at the root of the filesystem, so it is up to the package maintainer to make sure the package installs safely under very little assumptions. In the case of most debian packages, I would assume (someone can feel free to correct me here) that they simply untar and provide a top level package.

For example, say the package is "virtualenv", you'd end up with /usr/lib/python2.x/site-packages/virtualenv. If you install it with easy_install you'd get something like /usr/lib/python2.x/site-packages/virtualenv.egg-link that might point to /usr/lib/python2.x/site-packages/virtualenv-1.2-2.x.egg which may be a directory or zipped egg. Pip does something similar although it doesn't use eggs and instead will place the top level package directly in the lib directory.

I might be off on the paths, but the point is that each method takes into account different needs. This is why tools like virtualenv are helpful as they allow you to sandbox your Python libraries such that you can have any combination you need of libraries and versions.

Setuptools also allows installing packages as multiversion which means there is not a singular module_name.egg-link created. To import those packages you need to use pkg_resources and the __import__ function.

Going back to your original question, if you are happy with the system python and plan on using virtualenv and pip to build environments for different applications, then installing virtualenv and / or pip at the system level using apt-get seems totally appropriate. One word of caution though is that if you plan on upgrading your distributions Python, that may have a ripple effect through your virtualenvs if you linked back to your system site packages.

I should also mention that none of these options is inherently better than the others. They simply take different approaches. Using the system version is an excellent way to install Python applications, yet it can be a very difficult way to develop with Python. Easy install and setuptools is very convenient in a world without virtualenv, but if you need to use different versions of the same library, then it also become rather unwieldy. Pip and virtualenv really act more like a virtual machine. Instead of taking care to install things side by side, you just create an whole new environment. The downside here is that 30+ virtualenvs later you might have used up quite bit of diskspace and cluttered up your filesystem.

As you can see, with the many options it is difficult to say which method to use, but with a little investigation into your use cases, you should be able to find a method that works.


Do this:

curl "https://bootstrap.pypa.io/get-pip.py" -o "get-pip.py"
python get-pip.py
pip install virtualenv

See


Since virtualenvs contain pip by default, I almost never install pip globally. What I do ends up looking more like:

$ sudo apt-get install python-setuptools
$ curl -O http://python-distribute.org/distribute_setup.py
$ sudo python distribute_setup.py
$ sudo easy_install virtualenv

I then proceed to install and set up virtualenvwrapper to my liking and off I go. it might also be worthwhile to take a look at Jeremy Avnet's virtualenv-burrito:

https://github.com/brainsik/virtualenv-burrito


@ericholscher says on Twitter, "The one in the official docs.."

It's a great point, you should do what the docs say.

Quoted from the official pip installation instructions at http://www.pip-installer.org/en/latest/installing.html:

$ curl -O https://github.com/pypa/virtualenv/raw/master/virtualenv.py
$ python virtualenv.py my_new_env
$ . my_new_env/bin/activate
(my_new_env)$ pip install ...

Starting from distro packages, you can either use:

sudo apt-get install python-virtualenv

which lets you create virtualenvs, or

sudo apt-get install python{,3}-pip

which lets you install arbitrary packages to your home directory.

If you're used to virtualenv, the first command gives you everything you need (remember, pip is bundled and will be installed in any virtualenv you create).

If you just want to install packages, the second command gives you what you need. Use pip like this:

pip install --user something

and put something like

PATH=~/.local/bin:$PATH

in your ~/.bashrc.


If your distro is ancient and you don't want to use its packages at all (except for Python itself, probably), you can download virtualenv, either as a tarball or as a standalone script:

wget -O ~/bin/virtualenv https://raw.github.com/pypa/virtualenv/master/virtualenv.py
chmod +x ~/bin/virtualenv

If your distro is more of the bleeding edge kind, Python3.3 has built-in virtualenv-like abilities:

python3 -m venv ./venv

This runs way faster, but setuptools and pip aren't included.


To install pip on a mac (osx), the following one liner worked great for me:

sudo easy_install pip

In Raspbian, there is even no need to mention python2.7. Indeed this is best way to install pip if python version in less then 2.7.9.

curl --silent --show-error --retry 5 https://bootstrap.pypa.io/get-pip.py | sudo python

Thanks to @tal-weiss


https://github.com/pypa/pip/raw/master/contrib/get-pip.py is probably the right way now.


I use get-pip and virtualenv-burrito to install all this. Not sure if python-setuptools is required.

# might be optional. I install as part of my standard ubuntu setup script
sudo apt-get -y install python-setuptools

# install pip (using get-pip.py from pip contrib)
curl -O https://raw.github.com/pypa/pip/develop/contrib/get-pip.py && sudo python get-pip.py

# one-line virtualenv and virtualenvwrapper using virtualenv-burrito
curl -s https://raw.github.com/brainsik/virtualenv-burrito/master/virtualenv-burrito.sh | bash

On Debian the best way to do it would be

sudo apt-get install python-pip


The former method is fine. The only problem I can see is that you might end up with an old version of setuptools (if the apt repository hasn't been kept up-to-date..

참고URL : https://stackoverflow.com/questions/5585875/what-is-the-official-preferred-way-to-install-pip-and-virtualenv-systemwide

반응형