Traditionally, if you would like to setup a private python repository, it requires hosting and setting up a web server:
https://packaging.python.org/en/latest/guides/hosting-your-own-index/
There is an alternate way by which you can easily setup a local folder/directory or a network share drive as a private python repository. This could be useful for local testing or if you are looking for a quick solution for just publishing your packages to a network share drive for your team to use within your organization.
The way to do this is, configuring your folder/share drive path to pip’s find-links. There are multiple ways to do this:
- Using Terminal
- Using pip File
Using pip file is recommended, as it would be persisting.
Using Terminal
In Windows Command Prompt:
Configuring the folder/share drive path to the environment variable - PIP_FIND_LINKS.
For example, if you are having the python packages in a folder called “PyRepo” in D: drive, then the commands would be:
pipenv shell
set PIP_FIND_LINKS=D:\\PyRepo
pipenv install simple_pypackage
In Git Bash:
Equivalently in git bash,
PIP_FIND_LINKS=D:\\PyRepo
pipenv install simple_pypackage
One issue you might face with this approach is that, setting of the environment variable within the virtual environment would not be persisting, requiring you to set the environment variable each time you activate it.
Using pip File (Recommended)
Alternatively, you can setup the find-links in pip file, which would be persisiting. A system has multiple pip files, which are located at:
- Global:
C:\ProgramData\pip\pip.ini
- User:
%APPDATA%\pip\pip.ini
- Site:
%VIRTUAL_ENV%\pip.ini
Key to be added to the pip configuration file:
[global]
find-links =
D:\\PyRepo1
D:\\PyRepo2
Depending on your requirement, you can add the above contents to any one of the above 3 pip.ini files.
Multiple paths for find-links can be separated by space or new line character.
You can either do this manually or programmatically. To update the above configuration programmatically, you can use the below command:
pip config <file_option> set <section>.<key> <value>
To update the configuration to the global pip file and use the ‘global’ section in the configuration file, below is the command:
pip config --global set global.find-links 'D:\\PyRepo1 D:\\PyRepo2'
No comments:
Feel free to leave a piece of your mind.