What package management tools should I use for python?

Asked 2 years ago, Updated 2 years ago, 70 views

ruby allows you to manage the packages you need for each project with gemfile, but
What should I do with python?

By the way, we are planning to develop using django.

python django

2022-09-29 21:57

4 Answers

If it is equivalent to gemfile, I think you can use pip requirements.txt.

 pip freeze>requirements.txt

can collect the current environment state

 pip install-r requirements.txt

allows you to install the same package in a different environment.

For example, if you want to apply the same version that you installed in a virtualenv directory to a different directory

For Windows, python 2.7.
On Linux and elsewhere, the scripts\activate command should be .bin/activate.I think I can do the same.

Virtualenv keeps the machine environment clean.
If you have not deployed virtualenv, install it as pip install virtualenv.

I have omitted a lot of course.
As of today, if you do not specify a version of django, 1.8 will be installed, but I dare to specify 1.7

.
D:\Work\so8754>virtualenvyyy
New python executable in yyy\Scripts\python.exe
Installing setup tools, pip... done.

D:\Work\so8754>cdyyyy
D:\Work\so8754\yyy>Scripts\activate

(yyy) D:\Work\so8754\yyy> pip install django==1.7
Successfully installed django-1.7

(yyy) D:\Work\so8754\yyyy> pip install pillow
Successfully installed pillow-2.8.1

(yyy) D:\Work\so8754\yyyy> pip freeze>requirements.txt
(yyy) D:\Work\so8754\yyy>deactivate
D:\Work\so8754\yyy>

The requirements.txt are as follows:

Django==1.7
Pillow== 2.8.1

Use this file to install the same package in a different directory.

D:\Work\so8754\yyy>cd..
D:\Work\so8754>virtualenvzzz
D:\Work\so8754>cdzzz
D:\Work\so8754\zzz>scripts\activate
(zzz) D:\Work\so8754\zzz>copy..\yyy\requirements.txt.
        One file has been copied.

(zzz) D:\Work\so8754\zzz> pip install-r requirements.txt
Collecting Django==1.7 (from-r requirements.txt(line1))
  Using cached Django-1.7-py2.py3-none-any.whl
Collecting Pillow==2.8.1 (from-r requirements.txt(line2))
  Using cached Pillow-2.8.1-cp27-none-win32.whl
Installing collected packages: Pillow, Django


Successfully installed Django-1.7 Pillow-2.8.1
(zzz) D:\Work\so8754\zzz>

You will see that django contains 1.7

Also, if you want to update to a different version, first rewrite zzz\requirements.txt as follows

Django
Pillow== 2.8.1

I didn't specify the version of Django, so I'll specify the latest version (Django==1.8 is acceptable depending on the usage).
Run the following command:

(zzz)D:\Work\so8754\zzz>pip install --upgrade-r requirements.txt
Requirement already up-to-date: Pillow==2.8.1...
...
      Successfully uninstalled Django-1.7
Successfully installed Django-1.8

You will find that Django 1.7 is uninstalled and 1.8 is installed.

If you use virtualenvwrapper, you could have created it as the mkvirtualenv environment name -r requirements.txt and installed it at the same time.


2022-09-29 21:57

What about pip that comes with Python 3.4 by default?


2022-09-29 21:57

As it says "per project", I will probably answer with the assumption that each project will use a different library.

There is a tool called virtualenv that can handle multiple environments with different Python versions and dependent libraries.
There is also a virtualenvwrapper that wraps this.

These tools will create a dedicated environment for the project and install the library packages that depend on that particular environment with setuptools (easy_install command) or pip.


2022-09-29 21:57

Python Professional Programming 2nd Edition Chapters 3 and 9 have detailed the story.Basically, it's exactly what Freedion wrote.


2022-09-29 21:57

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.