https://qiita.com/ganariya/items/fb3f38c2f4a35d1ee2e8
In order to study Python, I copied a swarm intelligence library called acopy.
In acopy, many interesting Python grammars and idioms are used, and it is summarized that it is convenient among them.
This time, I will talk about batch installation and export of Python packages.
pip
pip is the official Python package manager. You can easily install third-party libraries with pip only.
Older languages can be very cumbersome to install this library Python pip Nodejs npm It is very convenient to have a package manager.
By using pip
pip install library name
You can install the library in the form of.
However, for example, when you want to use a repository written by another person in Git You may need a ton of libraries to install.
So, it's called requirements.txt
By reading the version name of the library to be used and the text file that wrote the name
It can be installed all at once.
requirements.txt
alabaster==0.7.12
Babel==2.7.0
beautifulsoup4==4.8.1
boto==2.49.0
boto3==1.10.1
The contents are as above.
In the directory where requirements.txt exists
pip install -r requirements.txt
You can give it as.
After loading the package, export the package In other words, it is possible to identify all the packages used in the project so that they can be installed immediately in other environments.
pip freeze
When you type the command
alabaster==0.7.12
Babel==2.7.0
beautifulsoup4==4.8.1
boto==2.49.0
boto3==1.10.1
botocore==1.13.1
cachetools==3.1.1
As mentioned above, the terminal will display the library name and version.
Therefore, all you have to do is output this to a file with a pipe.
pip freeze > requirements.txt
If you put this requirements.txt in the GitHub repository I am happy to be able to install the package more easily.
I've seen bulk installs of packages.
If you use pipenv, it seems to automatically hit requirements.txt It seems that a file that summarizes the packages will be created. It's very easy, so I'll try to touch it.
-Bulk installation of packages using requirements.txt with Python and pip
Recommended Posts