I embedded Python in an application. When the user installs a package or module via
{...}\myapp\python\python.exe setup.py install
the packages will be installed in
{...}\myapp\python\lib\site-packages
Is there any chance to use another directory instead by default?
CAUTION: Make sure you check option Add Python 3.5 to PATH . To change install location, click on Customize installation , then Next and enter C:\python35 (or another appropriate location) as the install location. If you didn�t check the Add Python 3.5 PATH option earlier, check Add Python to environment variables .
Installing Python Packages with Setup.py To install a package that includes a setup.py file, open a command or terminal window and: cd into the root directory where setup.py is located. Enter: python setup.py install.
The setup.py file may be the most significant file that should be placed at the root of the Python project directory. It primarily serves two purposes: It includes choices and metadata about the program, such as the package name, version, author, license, minimal dependencies, entry points, data files, and so on.
There are few things you need to take care for in order to do this. I did some research, and this is what I've found out:
This part is taken from Python's docs:
After the build command runs (whether you run it explicitly, or the install command does it for you), the work of the install command is relatively simple: all it has to do is copy everything under build/lib (or build/lib.plat) to your chosen installation directory.
If you don’t choose an installation directory—i.e., if you just run setup.py install—then the install command installs to the standard location for third-party Python modules. This location varies by platform and by how you built/installed Python itself.
Most Linux distributions include Python as a standard part of the system, so prefix and exec-prefix are usually both /usr on Linux. If you build Python yourself on Linux (or any Unix-like system), the default prefix and exec-prefix are /usr/local.
prefix
and exec-prefix
stand for the directories that Python is installed to, and where it finds its libraries at run-time.
You have a way for alternating the install location, up to a certain point: you can alternate the base dir, but not the installation scheme
The Distutils install command is designed to make installing module distributions to an alternate location simple and painless. The basic idea is that you supply a base directory for the installation, and the install command picks a set of directories (called an installation scheme) under this base directory in which to install files. The details differ across platforms, so read whichever of the following sections applies to you.
The idea behind the “home scheme” is that you build and maintain a personal stash of Python modules. This scheme’s name is derived from the idea of a “home” directory on Unix, since it’s not unusual for a Unix user to make their home directory have a layout similar to /usr/ or /usr/local/. This scheme can be used by anyone, regardless of the operating system they are installing for.
python setup.py install --home=<dir>
The --home
option defines the installation base directory. Files are installed to the following directories under the installation base as follows:
modules home/lib/python
scripts home/bin
data home
C headers home/include/python/distname
Then you'll need to modify Python's search path in order to locate the new location.
You can also use --prefix option which defines the installation base
python setup.py install --prefix=
. Read more about it here
To sum it up, you can change the home directory, but the site-packages hierarchy will be built in it.
To add new site-packages directory add that new directory path to the path configuration file.
The path configuration file will let you add an additional site-packages directory. If you don't want existing site-packages directory you can remove it from the PYTHON_PATH.
echo "new_site-package_directory" > your_site_packages_path/usrlocal.pth
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With