Install python wheel file without using pip - python

Is it possible to install a Python wheel without using pip? I always have issues with installing with pip, so I usually install libraries manually by copying and pasting. I'm wondering if there is a way to do wheel files in a similar manner.

I'm assuming you have internet access, but you don't have a working pip installation.
Download the pip wheel:
wget https://files.pythonhosted.org/packages/0f/74/ecd13431bcc456ed390b44c8a6e917c1820365cbebcb6a8974d1cd045ab4/pip-10.0.1-py2.py3-none-any.whl
To find the url of a release in the first place, you can get the index json endpoint. For example:
$ curl -s https://pypi.org/pypi/pip/json | jq ".urls[0].url"
"https://files.pythonhosted.org/packages/0f/74/ecd13431bcc456ed390b44c8a6e917c1820365cbebcb6a8974d1cd045ab4/pip-10.0.1-py2.py3-none-any.whl"
For users not scripting this but just doing once-off, you may prefer to simply download a pip wheel using your browser. In that case, look for the latest release files here: https://pypi.org/project/pip/#files
Now you have a wheel for pip, and some other wheel file you want to install. You can actually "execute" the pip wheel file to install the other wheel file. For example, if you were trying to install setuptools v39.0.1 from bdist, the command would look like this:
$ python pip-10.0.1-py2.py3-none-any.whl/pip install --no-index setuptools-39.0.1-py2.py3-none-any.whl
Processing ./setuptools-39.0.1-py2.py3-none-any.whl
Installing collected packages: setuptools
Successfully installed setuptools-39.0.1
You will now have a working setuptools installation, even with no pip installation.
In case you were wondering, yes you can use the same trick to install pip itself. That command would look like this:
python pip-10.0.1-py2.py3-none-any.whl/pip install --no-index pip-10.0.1-py2.py3-none-any.whl
And now you should have a working pip installation, associated with whichever interpreter this python executable is pointing at.

It is. Actually .whl files are just zip archives, so you can just extract their content and play with libraries path variable to make it work.
Yet it is really bad practice.

Related

pygame looks like a filename, but the file does not exist

I decided to try to install pygame and have run into this problem:
Requirement 'pygame-1.9.3-cp37-cp37m-win32.whl' looks like a filename, but the file does not exist
pygame-1.9.3-cp37-cp37m-win32.whl is not a supported wheel on this platform.
Everything worked up till this point and I'm so close to installing pygame. Also this is the thing that I typed:
pip install pygame-1.9.3-cp37-cp37m-win32.whl
You normally use a tool like pip to install wheels. Leave it to the tool to discover and download the file if this is for a project hosted on PyPI.
For this to work, you do need to install the wheel package:
Pip install wheel
You can then tell pip to install the project (and it'll download the wheel if available), or the wheel file directly:
pip install project_name # discover, download and install
pip install wheel_file.whl # directly install the wheel
The wheel module, once installed, also is runnable from the command line, you can use this to install already-downloaded wheels:
python -m wheel install wheel_file.whl
Also see the wheel project documentation.

Manually set package as installed in Python/pip

I'm installing the openbabel package, and it can automatically generate the necessary Python libraries during compilation. This saves a good chunk of time, since installing from source via pip takes a few minutes, and that time can be rolled into the initial compilation.
I've listed it as a requirement in my requirements.txt file, but when I go to install (pip install -r requirements.txt), it attempts to reinstall the openbabel Python library. When I run pip show or pip list, openbabel doesn't show up.
Is there a way to manually mark a package as installed so pip thinks it's installed, even if it can't find the package? Or is there a file I can create that pip will use that will tell it openbabel is installed?
Create an empty .egg-info file in your site-packages directory.
For example, on my machine I did touch /usr/lib64/python3.6/site-packages/GLWindow-1.8.0-py3.6.egg-info to trick pip3 into thinking that I've installed GLWindow.

Unable to install pip on suse

Pretty new to linux/suse and python so excuse me if I cause some simple questions.
I've search through stackoverflow and haven't gotten a result for my question.
I'm running on Windows with a Virtual machine using SUSE. I'm trying to install py.test, but to install it, it needs either pip or easy_install. I've heard pip is preferred over easy_install, so I tried installing that with get-pip.py.
I run it with
python get-pip.py
and it tells me it has been installed, this is what it ouputs
Collecting pip
Using cached pip-6.1.1-py2.py3-none-any.whl
Collecting setuptools
Using cached setuptools-15.1-py2.py3-none-any.whl
Installing collected packages: pip, setuptools
Successfully installed pip-6.1.1 setuptools-15.1
I tried running
pip install -U pytest
however the command pip has not been found. I also looked into python-pip package via openSUSE, though I'm not sure how to open a .ymp file through a VM.
Would I have to add a path for it to work? Pointers would be appreciated.
It looks like pip was unstalled by a regular user, so it was installed under the user's homedir, thus needs to be explicitly added to the path.
On openSUSE I'd suggest installing it using YaST (as root) and it'll end up in /usr/bin/pip, shareable by all users. Here's how it looks like on openSUSE 13.2:
$> which pip
/usr/bin/pip
$> rpm -qf /usr/bin/pip
python3-pip-1.5.6-2.1.3.noarch
Just search for pip in the software management tool.
Also many additional python packages/modules come prepackaged as openSUSE RPMs, better check the software management tool 1st.

How do I install Python libraries in wheel format?

I was looking for a tutorial on how to install Python libraries in the wheel format.
It does not seem straightforward so I'd appreciate a simple step by step tutorial how to install the module named "requests" for CPython.
I downloaded it from: https://pypi.python.org/pypi/requests and now I have a .whl file. I've got Python 2.7 and 3.3 on Windows, so how do I install it so all the other Python scripts I run can use it?
You want to install a downloaded wheel (.whl) file on Python under Windows?
Install pip on your Python(s) on Windows (on Python 3.4+ it is already included)
Upgrade pip if necessary (on the command line)
pip install -U pip
Install a local wheel file using pip (on the command line)
pip install --no-index --find-links=LocalPathToWheelFile PackageName
Option --no-index tells pip to not look on pypi.python.org (which would fail for many packages if you have no compiler installed), --find-links then tells pip where to look for instead. PackageName is the name of the package (numpy, scipy, .. first part or whole of wheel file name). For more informations see the install options of pip.
You can execute these commands in the command prompt when switching to your Scripts folder of your Python installation.
Example:
cd C:\Python27\Scripts
pip install -U pip
pip install --no-index --find-links=LocalPathToWheelFile PackageName
Note: It can still be that the package does not install on Windows because it may contain C/C++ source files which need to be compiled. You would need then to make sure a compiler is installed. Often searching for alternative pre-compiled distributions is the fastest way out.
For example numpy-1.9.2+mkl-cp27-none-win_amd64.whl has PackageName numpy.
If you want to be relax for installing libraries for python.
You should using pip, that is python installer package.
To install pip:
Download ez_setup.py and then run:
python ez_setup.py
Then download get-pip.py and run:
python get-pip.py
upgrade installed setuptools by pip:
pip install setuptools --upgrade
If you got this error:
Wheel installs require setuptools >= 0.8 for dist-info support.
pip's wheel support requires setuptools >= 0.8 for dist-info support.
Add --no-use-wheel to above cmd:
pip install setuptools --no-use-wheel --upgrade
Now, you can install libraries for python, just by:
pip install library_name
For example:
pip install requests
Note that to install some library may they need to compile, so you need to have compiler.
On windows there is a site for Unofficial Windows Binaries for Python Extension Packages that have huge python packages and complied python packages for windows.
For example to install pip using this site, just download and install setuptools and pip installer from that.
To install wheel packages in python 2.7x:
Install python 2.7x (i would recommend python 2.78) - download the appropriate python binary for your version of windows . You can download python 2.78 at this site https://www.python.org/download/releases/2.7.8/
-I would recommend installing the graphical Tk module, and including python 2.78 in the windows path (environment variables) during installation.
Install get-pip.py and setuptools
Download the installer at
https://bootstrap.pypa.io/get-pip.py
Double click the above file to run it. It will install pip and setuptools [or update them, if you have an earlier version of either]
-Double click the above file and wait - it will open a black window and print will scroll across the screen as it downloads and installs [or updates] pip and setuptools --->when it finishes the window will close.
Open an elevated command prompt - click on windows start icon, enter cmd in the search field (but do not press enter), then press ctrl+shift+. Click 'yes' when the uac box appears.
A-type
cd c:\python27\scripts
[or cd \scripts ]
B-type
pip install -u
Eg to install pyside, type pip install -u pyside
Wait - it will state 'downloading PySide or -->it will download and install the appropriate version of the python package [the one that corresponds to your version of python and windows.]
Note - if you have downloaded the .whl file and saved it locally on your hard drive, type in
pip install --no-index --find-links=localpathtowheelfile packagename
**to install a previously downloaded wheel package you need to type in the following command
pip install --no-index --find-links=localpathtowheelfile packagename
Have you checked this http://docs.python.org/2/install/ ?
First you have to install the module
$ pip install requests
Then, before using it you must import it from your program.
from requests import requests
Note that your modules must be in the same directory.
Then you can use it.
For this part you have to check for the documentation.
Install distribute by downloading and running distribute_setup.py. This will make easy_install available, and from there you can install pip with easy_install pip. Then you can run pip install CAGE. Using pip to install things is a lot easier than messing with manually running setup.py, because pip can do things like:
automatically resolve dependencies
show you a list of all installed packages and their versions
install a set of specified packages from a requirements.txt
upgrade and uninstall packages
work with virtualenv
If you're on Windows, the one downside of pip occurs when there are C library dependencies, as pip will want a C toolchain installed so it can compile things. If that is the case, then there are two options. If there are precompiled binaries on PyPI, then just run easy_install package instead; easy_install knows how to use binary packages. You can also check Christoph Gohlke's site for executable installers of many binary packages. These can also be installed by easy_install if you want to use them with a virtualenv (just point it to the path of the .exe) or you can click and run if you don't care about virtualenv.
The main point is that no matter what route you choose to install packages, at no point are you ever moving around files by hand. You need to get out of the mindset of "I extracted this archive, where do I put these .py files?" That's not how it works. You're either running pip, running easy_install, running setup.py, clicking on an installer package, or using your distribution's installer. At no point are you ever doing anything by hand with the files directly.
Once you have a library downloaded you can execute this from the MS-DOS command box:
python setup.py install
The setup.py is located inside every library main folder.
For windows, there are automatic installer packages available at this site
It includes most of the python packages.
But the best way for it is of course using pip.
You don't need to download exclusively from the website. Just make sure you have pip (which you probably will if you have python installed). Just open your Command Prompt (CMD) and run the command:
pip install pygame
It will automatically download the correct whl version of pygame compatible with your configuration of PC. Make sure you remember the version which appears while "downloading" as this is the compatible version of .whl packages you shall be looking for in the future.
Simple steps to install python in Ubuntu:
Download Python
$ cd /usr/src
$ wget https://www.python.org/ftp/python/3.6.0/Python-3.6.0.tgz
Extract the downloaded package
$ sudo tar xzf Python-3.6.0.tgz
Compile Python source
$ cd Python-3.6.0
$ sudo ./configure
$ sudo make altinstall
Note make altinstall is used to prevent replacing the default python binary file /usr/bin/python.
check the python version
# python3.6 -V
i have write the answer here
How to add/use libraries in Python (3.5.1)
but no problem will rewrite it again
if u have or you can create a file requirements.txt which contains the libraries that you want to install for ex:
numpy==1.14.2
Pillow==5.1.0
You gonna situate in your folder which contains that requirements.txt in my case the path to my project is
C:\Users\LE\Desktop\Projet2_Sig_Exo3\exo 3\k-means
now just type
python -m pip install -r ./requirements.txt
and all the libararies that you want gonna install
C:\Users\LE\Desktop\Projet2_Sig_Exo3\exo 3\k-means>python -m pip install -r ./requirements.txt

How to use Python's pip to download and keep the zipped files for a package?

If I want to use the pip command to download a package (and its dependencies), but keep all of the zipped files that get downloaded (say, django-socialregistration.tar.gz) - is there a way to do that?
I've tried various command-line options, but it always seems to unpack and delete the zipfile - or it gets the zipfile, but only for the original package, not the dependencies.
pip install --download is deprecated. Starting from version 8.0.0 you should use pip download command:
pip download <package-name>
The --download-cache option should do what you want:
pip install --download-cache="/pth/to/downloaded/files" package
However, when I tested this, the main package downloaded, saved and installed ok, but the the dependencies were saved with their full url path as the name - a bit annoying, but all the tar.gz files were there.
The --download option downloads the main package and its dependencies and does not install any of them. (Note that prior to version 1.1 the --download option did not download dependencies.)
pip install package --download="/pth/to/downloaded/files"
The pip documentation outlines using --download for fast & local installs.
I always do this to download the packages:
pip install --download /path/to/download/to_packagename
OR
pip install --download=/path/to/packages/downloaded -r requirements.txt
And when I want to install all of those libraries I just downloaded, I do this:
pip install --no-index --find-links="/path/to/downloaded/dependencies" packagename
OR
pip install --no-index --find-links="/path/to/downloaded/packages" -r requirements.txt
Update
Also, to get all the packages installed on one system, you can export them all to requirement.txt that will be used to intall them on another system, we do this:
pip freeze > requirement.txt
Then, the requirement.txt can be used as above for download, or do this to install them from requirement.txt:
pip install -r requirement.txt
REFERENCE: pip installer
pip wheel is another option you should consider:
pip wheel mypackage -w .\outputdir
It will download packages and their dependencies to a directory (current working directory by default), but it performs the additional step of converting any source packages to wheels.
It conveniently supports requirements files:
pip wheel -r requirements.txt -w .\outputdir
Add the --no-deps argument if you only want the specifically requested packages:
pip wheel mypackage -w .\outputdir --no-deps
Use pip download <package1 package2 package n> to download all the packages including dependencies
Use pip install --no-index --find-links . <package1 package2 package n> to install all the packages including dependencies.
It gets all the files from CWD.
It will not download anything
In version 7.1.2 pip downloads the wheel of a package (if available) with the following:
pip install package -d /path/to/downloaded/file
The following downloads a source distribution:
pip install package -d /path/to/downloaded/file --no-binary :all:
These download the dependencies as well, if pip is aware of them (e.g., if pip show package lists them).
Update
As noted by Anton Khodak, pip download command is preferred since version 8. In the above examples this means that /path/to/downloaded/file needs to be given with option -d, so replacing install with download works.
installing python packages offline
For windows users:
To download into a file
open your cmd and folow this:
cd <*the file-path where you want to save it*>
pip download <*package name*>
the package and the dependencies will be downloaded in the current working directory.
To install from the current working directory:
set your folder where you downloaded as the cwd then follow these:
pip install <*the package name which is downloded as .whl*> --no-index --find-links <*the file locaation where the files are downloaded*>
this will search for dependencies in that location.
All the answers mentioned in this thread assume that the packages will be downloaded on the same OS configuration as the target OS where it has to be installed.
In my personal experience i was using windows as my work machine and had to download packages for linux environment and have seen people doing vice versa as well. I had done some extensive googling, and found sodim.dev.
All i had to do was upload requirements.txt file and select the environment configuration like OS and python version and it gives out a csv with download url, source code url etc
I guess in the backend this app spins up the OS VM as requested and installs that particular python version and then generates the report, because it does take about 15-20 minutes for 30-50 packages.
P.S.: I work in an offline environment, where security is of very high concern, and downloading packages are not that frequent. We whitelist source code and download urls for each individual requests and then after running some appsec tools, we approve/reject the source code to be downloaded.
I would prefer (RHEL) - pip download package==version --no-deps --no-binary=:all:

Categories