Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add own index to pip running in virtualenv?

  • I have a virtualenv with pip inside.
  • I have my own package index.
  • I want to add this package to pip to avoid invoking pip install some_package -i my_index all the time
  • I want to add this index only to this specific pip instance running in virtualenv.

In that case, which file should I modify and how?

like image 387
mnowotka Avatar asked Jun 10 '13 13:06

mnowotka


People also ask

Where is pip config in VENV?

On Unix and macOS the file is $VIRTUAL_ENV/pip. conf. On Windows the file is: %VIRTUAL_ENV%\pip. ini.

How do I enable pip in virtual environment?

To create a virtual environment, go to your project's directory and run venv. If you are using Python 2, replace venv with virtualenv in the below commands. The second argument is the location to create the virtual environment. Generally, you can just create this in your project and call it env .

What is the default pip Index URL?

Base URL of the Python Package Index (default https://pypi.org/simple).


2 Answers

I run into the same problem, and found that pip support this in current version de facto https://pip.pypa.io/en/latest/user_guide.html#config-file

Inside a virtualenv:

On Unix and Mac OS X the file is $VIRTUAL_ENV/pip.conf
On Windows the file is: %VIRTUAL_ENV%\pip.ini

like image 137
tryer3000 Avatar answered Sep 21 '22 22:09

tryer3000


I never tried using my own index, but after some research this article should cover what you want to do.

Basically you need to add the following to your ~/.pip/pip.conf (on Windows systems, located at %HOME%\pip\pip.ini):

[global]
index-url = http://my.pypi.index/comes/here

The problem is that you will have a global definition for all your projects and what you want is a definition for all your users in the specific project. From pip documentation you can alter the config file lookup by using the environment var PIP_CONFIG_FILE

You could edit the virtual-env-folder/bin/activate script to include this environment var, but the problem is that creating a new virtual environment would lose this change and would not be possible to automate. What you can do is creating the .pip/pip.conf file in the root of your project and creating a simple activate-virtual-env script also on the root of the project with the following:

pushd $(dirname $0)
export PIP_CONFIG_FILE="$(pwd)/.pip/pip.conf"
source "$(pwd)/virtual-env-folder/bin/activate"
popd

and instruct your users to source this file instead of virtual-env-folder/bin/activate

like image 40
Bruno Penteado Avatar answered Sep 17 '22 22:09

Bruno Penteado