I'm trying to deploy a new version of a project I've been working on. I zip the package into a .tar.gz file using the standard python setup.py sdist command, and then install the package using python -m pip install x.tar.gz.
All the files which are required are present in the archive itself (the .tar.gz file) but for some reason pip skips installing one of these, a binary file containing some lookup tables. Moreover, I think this happens only on linux (I make the package itself using Windows, and here everything works fine). I would think that this might have something to do with using sdist instead of bdist, but with previous versions I've had no issues of this kind, despite using the same method. I'm not sure if there is any architecture dependency at play here. Are all binary files architecture dependent?
Any ideas regarding what might be the cause of this?
Related
I am making a python package that has some dependencies not hosted on PyPI or other indexes. I'd like to include those .whl dependencies in my repo/package, and install them from local files when the user pip installs my package.
I could add code to call pip directly on those files within my setup.py file, but I'm not sure of a reliable way to do that, especially considering if the user passed special arguments to pip originally.
Is there a proper way to do this? Or is it not something well supported by pip/setuptools?
I'm new to installing python packages.
I just installed Biopython by going to the source code (downloaded from github) and running:
python setup.py build
My question is - can I now throw out the source code files (in folder) on my desktop? Or do I have to keep them there for the Biopython package to work?
Possibly, but likely not.
If you were to install it, like this:
python setup.py install
… then you could throw away the whole source directory. That's exactly what pip does, in effect. (Speaking of pip, for most packages, it's better to use pip to install them. That way you can, for example, uninstall them, or upgrade them, or list them out so you know what you had installed before upgrading Python or moving to a new machine. The main exception is, of course, packages that don't work with pip, which you'll discover when you try and it fails.:)
But if all you did was build it, so you can run it from within its own directory, any top-level scripts aren't compiled, other modules may be compiled but may still expect to find source somewhere, etc. (Of course you can always test and see—back up the directory, delete all the .py files, try it, and if it doesn't work, restore the backed up copy…)
We are shipping our product to customers location who may or may not have python and other libraries installed, so can we reduce our python script into an independent executable with python and other required libraries included , so are there other ideas ?
You can use py2exe it does exactly what you need, and its very easy to use. I have used it on one of my projects which are online and used daily.
http://www.py2exe.org/
and here is their tutorial:
http://www.py2exe.org/index.cgi/Tutorial
You can deliver a package with Python and then apply one of these two methods:
Package With python + virtualenv
There's many solutions for that. One I like is virtualenv, which can allow you to deploy a specific configuration of a Python project (with dependencies) on another machines.
Package With python + pip
Another way is to use pip and write a requirements.txt file at the root of your project, which contains every dependency (1 per line), for example:
django>=1.5.4
pillow
markdown
django-compressor
By doing pip -r requirements.txt in the root dir, the program will install packages needed.
See also:
How do you use pip, virtualenv and Fabric to handle deployment?
Pip installer documentation
Virtualenv documentation
I have read the documentation but I don't understand.
Why do I have to use distutils to install python modules ?
Why do I just can't save the modules in python path ?
You don't have to use distutils. You can install modules manually, just like you can compile a C++ library manually (compile every implementation file, then link the .obj files) or install an application manually (compile, put into its own directory, add a shortcut for launching). It just gets tedious and error-prone, as every repetive task done manually.
Moreover, the manual steps I listed for the examples are pretty optimistic - often, you want to do more. For example, PyQt adds the .ui-to-.py-compiler to the path so you can invoke it via command line.
So you end up with a stack of work that could be automated. This alone is a good argument.
Also, the devs would have to write installing instructions. With distutils etc, you only have to specify what your project consists of (and fancy extras if and only if you need it) - for example, you don't need to tell it to put everything in a new folder in site-packages, because it already knows this.
So in the end, it's easier for developers and for users.
what python modules ? for installing python package if they exist in pypi you should do :
pip install <name_of_package>
if not, you should download them .tar.gz or what so ever and see if you find a setup.py and run it like this :
python setup.py install
or if you want to install it in development mode (you can change in package and see the result without installing it again ) :
python setup.py develop
this is the usual way to distribute python package (the setup.py); and this setup.py is the one that call disutils.
to summarize this distutils is a python package that help developer create a python package installer that will build and install a given package by just running the command setup.py install.
so basically what disutils does (i will sit only important stuff):
it search dependencies of the package (install dependencies automatically).
it copy the package modules in site-packages or just create a sym link if it's in develop mode
you can create an egg of you package.
it can also run test over your package.
you can use it to upload your package to pypi.
if you want more detail see this http://docs.python.org/library/distutils.html
You don't have to use distutils to get your own modules working on your own machine; saving them in your python path is sufficient.
When you decide to publish your modules for other people to use, distutils provides a standard way for them to install your modules on their machines. (The "dist" in "distutils" means distribution, as in distributing your software to others.)
I'm working with PyInstaller under Python 2.6, which is only partially supported due to the mess MS have created with their manifest nonense which now affects Python since it is now MSVC8 compiled.
The problem is that the manifest embedding support relies on the pywin32 extensions in order to build which is a pain because without including the host's site-packages folder when I create the virtualenv (kinda defeats the point in a build environment) I cannot find a way to install the required extensions so they are accessible to PyInstaller.
Has anyone found a solution to this issue?
I found http://old.nabble.com/Windows:-virtualenv-and-pywin32--td27658201.html (now a dead link) which offered the following solution:
Browse http://sourceforge.net/projects/pywin32/files/ for the URL of the exe you want
Activate your virtualenv
Run easy_install http://PATH.TO/EXE/DOWNLOAD
This works with modern versions of setuptools (circa February 2014, reported by tovmeod in the comments).
If you are using an old version of setuptools (or distribute it merged back into setuptools), you may get this error message:
error: c:\users\blah\appdata\local\temp\easy_install-ibkzv7\pywin32-214.win32-py2.6.exe is not a valid distutils Windows .exe
In which case:
Download the exe yourself
Activate your virtualenv
Run easy_install DOWNLOADED_FILE.exe
I rather hopefully tried "pip install" rather than "easy_install", but this didn't work, and likely never will (citation needed).
Finally, I found but haven't tested a solution at http://www.mail-archive.com/python-list#python.org/msg272040.html which is:
Solved this by copying the pywin32.pth file into my virtualenv site-packages
and editing the file to point to the path.
If the other options don't work for you, maybe this will?
For Python 2.7 or 3.x use pypiwin32.
pip install pypiwin32
OK, well since I had to find a way forward I improvised. I've internally created a git repository with a hacked-together version of pywin32 that will install within a virtualenv using the standard setup.py script. It took a lot of fiddling to make it work right but I managed to get it to load and the dependent code now works as I need it to. If people feel this would be of benefit to the community please post a comment: if I get enough I'll try and put something up on my github account.
This may have been improved since previous answer, since I've successfully installed pywin32 on sandbox on several machines without any specific "hacks" :
$ virtualenv sandbox
$ sandbox\scripts\activate
(sandbox) $ git clone https://github.com/Travis-Sun/pywin32.git
(sandbox) $ cd pywin32
(sandbox) $ python setup.py install
Tested with following environment :
windows 7
git
python 2.7.10 with virtualenv
VS2008. It may also work (but I've not tested yet) with
http://www.microsoft.com/en-us/download/details.aspx?id=44266
Edit: Scratch this for now, appears to be some problems with the installation still...
I got rather tired of the whole situation, and just created a set of converted wheels ("wheel convert <.exe>"). I'll try and keep them maintained for the most recent build, but do shout if there are any issues.
https://tr00st.co.uk/python/wheel/pywin32/
Installation can be done easily using pip and pointing to the package matching your version and architecture. For example, for Python 3.5/amd64:
pip install https://tr00st.co.uk/python/wheel/pywin32/pywin32-219-cp35-none-win_amd64.whl
Caveat: The --upgrade process currently fails, as the uninstall procedure is unable to clean up after itself (Access Denied when cleaning up win32api.pyd) - this is only when removing the temporary directory, which can be manually deleted. Easiest way around this is to uninstall and reinstall instead of upgrading, then manually delete the temporary folder.