Home >Backend Development >Python Tutorial >Build your own pip source in Python environment

Build your own pip source in Python environment

高洛峰
高洛峰Original
2017-03-02 17:30:291533browse

1. Install the pip2pi tool:

##

pip install pip2pi

or:

git clone https://github.com/wolever/pip2pi
cd pip2pi
python setup.py install

2. Create a warehouse to store the software package:

mkdir /opt/python/soft/pypi.jb51.net

3. Download the software package And create an index:

Download a software package individually

pip2tgz /opt/python/soft/pypi.jb51.net/ routes==1.12.3

Download software packages in batches:

pip2tgz /opt/python/soft/pypi.jb51.net/ -r list/requirements.txt

Create index:

dir2pi /opt/python/soft/pypi.jb51.net/

Update index:

pip2acmeco uliweb=0.2.6 
pip2acmeco -r list/requirements.txt

4. Configure the web side with nginx:

Nginx server adds virtual host configuration:

server {
  listen 80;
  server_name pypi.jb51.net;
  root /opt/python/soft/pypi.jb51.net;
  location /{
   autoindex on;
   autoindex_exact_size off; #显示文件的大小
   autoindex_localtime on; #显示文件时间
   #limit_rate_after 5m; #5分钟后下载速度限制为200k
   limit_rate 200k;
  }
access_log logs/pypi.jb51.net.access.log main;
}

At this point, you have configured your own private pypi. When you need any software packages, you can just get them and put them in your own pypi;

In the same way, you can also package your own projects.

5. How to better use pypi source:

For example, install uliweb

pip install --index-url=http://www.php.cn/ uliweb

or


pip install -i uliweb

Is this very troublesome? Do you want to use your own pypi source by default? Well, it’s given to you here I have thought of a method:

Create the ~/.pip/pip.conf file under Linux. The file content is as follows

[global]
index-url = http://www.php.cn/

If It is a windows environment, create: %HOMEPATH%\pip\pip.ini

The content is the same as under Linux above.

We also recommend several better domestic pypi sources:

http://pypi.douban.com 豆瓣
 
http://pypi.hustunique.com 华中理工大学
 
http://pypi.sdutlinux.org 山东理工大学
 
http://pypi.mirrors.ustc.edu.cn 中国科学技术大学

PS: There are two ways to modify the source used by easy_install and pip
(from the mirror source e.pypi.python.org on Linux Download and install requests as an example):

Command mode: For one-time use, temporary modification

easy_install

easy_install -i http://e.pypi.python.org/simple requests

pip

pip install requests -i http://e.pypi.python.org/simple

Note: 1. The source path must include the /simple part; 2. When using pip, the -i parameter should be placed after install xxx

Modify (if not, create) the configuration file of easy_install/pip

easy_install: Write the following content in the ~/.pydistutils.cfg configuration file:

[easy_install]
index_url = http://e.pypi.python.org/simple

pip: Write in the ~/.pip/pip.conf configuration file:

[global]
index-url = http://e.pypi.python.org/simple


For more articles related to building your own pip source in the Python environment, please pay attention to the PHP Chinese website!


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn