How to manually install a pypi module without pip/easy_install?
Asked Answered
M

3

126

I want to use the gntp module to display toaster-like notifications for C/C++ software. I want to package all the dependencies for the software to be self-executable on another computer.

The gntp module is only available through the pip installer, which cannot be used (the computer running the software does not have an internet connection)

How can I install it from source?

I would prefer not to force the user to install easy_install/pip and manually add the pip path to the %PATH.

PS: I'm using Python 2.7 on a Windows machine.

Mistletoe answered 7/11, 2012 at 13:34 Comment(1)
Perhaps with python setup.py install?Executor
E
183
  1. Download the package
  2. unzip it if it is zipped
  3. cd into the directory containing setup.py
  4. If there are any installation instructions contained in documentation, read and follow the instructions OTHERWISE
  5. type in python setup.py install

You may need administrator privileges for step 5. What you do here depends on your operating system. For example in Ubuntu you would say sudo python setup.py install


EDIT- thanks to kwatford (see first comment)

To bypass the need for administrator privileges during step 5 above you may be able to make use of the --user flag. This way you can install the package only for the current user.

The docs say:

Files will be installed into subdirectories of site.USER_BASE (written as userbase hereafter). This scheme installs pure Python modules and extension modules in the same location (also known as site.USER_SITE).

More details can be found here: http://docs.python.org/2.7/install/index.html

Exarch answered 7/11, 2012 at 13:55 Comment(12)
pip/easy_install/setup.py usually accept a --user flag to install the package only for the current user, generally bypassing the need for admin access.Epirus
yeah it work : now I have to find a way to correctly set the environment variables for Python on Windows ...Mistletoe
For some reason I see this: ImportError: No module named 'setuptools' I found that here: pypi.python.org/pypi/setuptools/1.1.6 Although the install gave me exception errors, now the websocket module doesn't work at all, I think I'll give up on Python 3.3 on Windows at this point.Terni
@SSHThis : I have the same results with a package whose installation I'm trying to get working. Turning up verbosity gives "Because this distribution was installed --multi-version [...]" which is both false (only one version of python installed here) and unhelpful (using the documented "python -m easy_install [...]" is no help at all), I'm with you -- Python is unusable.Ostrander
I guess pip install target-package usually automatically installs/updates other packages on which target-package depends. Does this happens in case of setup.py approach? Or does zip of package contains all dependencies too? And do you mean we should be downloading python wheels instead of zips? Like these for numpy? If not where to find zips (for example for numpy)? (Am asking all this because I am forced to work behind corporate proxy where I have to struggle for every download :'( )Wanettawanfried
@Wanettawanfried your guess about pip is correct. In terms of setup.py, the standard is that it dowloads and installs the latest required packages. Look inside a setup.py file to see what it doesExarch
so it is not possible to download all dependancy packages offline using some script so that we can move all those dependency packages to target machine not having access to Internet (or is behind some proxy)?Wanettawanfried
you cant really download packages while offline... If you want to download them while outside of your silly work network then I would probably do the following: 1. make a virtualenv. 2. python setup.py install or pip install all the things you'll need. 3. run pip freeze to get a list of all packages and all versions. You can store this in a file (traditionally called requirements.txt'. Then if you want to download the packages so you can copy them to different machines you can use pip download [options] -r <requirements file>. This isn't the most efficient way. but easyExarch
@Wanettawanfried ^^^Exarch
There is a typo : contianed needs to be changed to contained. I cannot do it because the change has to be more than 6 characters,Tripersonal
I have Windows10. In command prompt, I add this line python setup.py install but I get the error: "Python was not found; run without arguments to install from the Microsoft Store, or disable this shortcut from Settings > Manage App Execution Aliases."Godbeare
@JustMe: you would need to install Python before you install any packages that require pythonExarch
N
5

To further explain Sheena's answer, I needed to have setup-tools installed as a dependency of another tool e.g. more-itertools.

Download

Click the Clone or download button and choose your method. I placed these into a dev/py/libs directory in my user home directory. It does not matter where they are saved, because they will not be installed there.

Installing setup-tools

You will need to run the following inside the setup-tools directory.

python bootstrap.py
python setup.py install

General dependencies installation

Now you can navigate to the more-itertools direcotry and install it as normal.

  1. Download the package
  2. Unpackage it if it's an archive
  3. Navigate (cd ...) into the directory containing setup.py
  4. If there are any installation instructions contained in the documentation contained herein, read and follow the instructions OTHERWISE
  5. Type in: python setup.py install
Nova answered 4/5, 2018 at 15:13 Comment(1)
hi, this solution is not working. there is no bootstrap.py file in setup-tools dir and on running python setup.py install it is giving me the same error that setuptools does not exist, and thats what this solution is for to install setup toolsLoki
N
4

Even though Sheena's answer does the job, pip doesn't stop just there.

From Sheena's answer:

  1. Download the package
  2. unzip it if it is zipped
  3. cd into the directory containing setup.py
  4. If there are any installation instructions contained in documentation contained herein, read and follow the instructions OTHERWISE
  5. type in python setup.py install

At the end of this, you'll end up with a .egg file in site-packages. As a user, this shouldn't bother you. You can import and uninstall the package normally. However, if you want to do it the pip way, you can continue the following steps.

In the site-packages directory,

  1. unzip <.egg file>
  2. rename the EGG-INFO directory as <pkg>-<version>.dist-info
  3. Now you'll see a separate directory with the package name, <pkg-directory>
  4. find <pkg-directory> > <pkg>-<version>.dist-info/RECORD
  5. find <pkg>-<version>.dist-info >> <pkg>-<version>.dist-info/RECORD. The >> is to prevent overwrite.

Now, looking at the site-packages directory, you'll never realize you installed without pip. To uninstall, just do the usual pip uninstall <pkg>.

Nasal answered 21/3, 2018 at 11:28 Comment(1)
What if I am installing a package from Anaconda repository and it doesn't have setup.py file?Reformer

© 2022 - 2024 — McMap. All rights reserved.