Specify the installation path method for the package based on python

  • 2021-01-06 00:39:29
  • OfStack

Usually python installation package will be the default in/usr/local/pythonx/lib/site - packages (linux), but we want to customize package installation path, sometimes like a path of the project, so don't have to install when deployed, as everybody knows, java did just that, java projects are put dependent lib in a directory, or compiler couldn't through, then in python, we can do this, the answer is yes.

In the easy_install official documentation, there are three ways to define the installation path of a package, as follows:

1. Use the --user parameter

After use - user parameters, easy_install will automatically create a home directory under the ~ /. local/lib/pythonxx/site packages/directory, and then put the packing inside. For example, install django so only easy_install --user django==2.0, or pip install django==2.0 --user, if it is the source code download, is python setup.py install --user.

2. Use the combination of environment variables PYTHONUSERBASE and --user

The first way to change the directory, but still fixed, through the PYTHONUSERBASE environment variable (do not know what is the environment variable or do not know how to set it can be: )), you can custom directory, such as my project directory is/opt/project, then I put PYTHONUSERBASE environment variable is set to/opt project third/so combination - user parameters after the package was installed in the/opt project/third lib/pythonxx/site - packages, much later, of course, a few level directory, innocuous.

3. Use virtualenv

This should be familiar to all of you, so I won't repeat it here.


Related articles: