How can I distribute the .py program without having to install all the libraries?

20

I'm learning Python and need to distribute a program, read about cx_Freeze and py2exe to generate an .exe. However, I do not mind distributing the program code together, so I do not see a need to generate an .exe.

How can I distribute the .py program without the user having to install all the libraries used in the program? Can I create an installer?

    
asked by anonymous 13.06.2015 / 02:47

3 answers

9

Well, I do not know if this is possible, but maybe you can do this to make it easier to install packages:

Using a .bat file you can install the libraries using pip, for example:

start /w pip install numpy 
start /w pip install matplotlib
start /w pip install qualquerOutraBiblioteca
...

If you need to pip in the system path, before the above code, put:

SETX PATH "%PATH%;C:\Python33\Scripts"

If you need to install the pip, put first

start /w python get-pip.py

Link to get-pip.py

About pip.

If you want to generate a .msi installer, take a look at pynsist .     

14.06.2015 / 03:53
4

Python has a package management ecosystem (libraries) integrated with both lignage and in-house packages.

PIP - a much-needed tool that became part of the new Python installs from Python 3.3 manually resolves the dependency issue for those in a hurry and does not want to leave the round package for third parties.

Of course, this assumes that your project is already running on a separate virtualenv, where the only libraries installed other than your own project are the ones you want to make sure they are installed on the target.

If you are not yet using Virtualenv for your development, take a look here: link (or, for Python > = 3.3 venv, which comes bundled with Python ): link

In this case, you can use PIP to create a file with the list of Python libraries installed in your project - type: pip freeze >requirements.txt in the terminal, with virtualenv enabled. This will automatically list the libraries installed in the "requirements.txt" file - whoever installs your program, after having the code in hand, and create virtualenv, you should type: pip -r requirements.txt .

Python developers accustomed to picking up and placing projects on sites like github will be able to install packages and libraries following this recommendation.

But that does not answer your question - if you want a lay user to install your program, having only Python installed, this is possible - but it gives you a little more work to get it right the first time, to the developer .

You will then use "setuptools" - a Python package made for, from information about your project that you put into a file named setup.py - This file is a small Python program where you put not only the dependencies of your project, (such as module build instructions, if there is part of the project in C or Cython), metadata about project version number, author, and use license, and so on.

setuptools causes setup.py to function as a full command line application with several options. One of them is even direct call python setup.py bdist_wininst - that in a properly configured Windows environment will generate an .EXE file that installs your application and its requirements (it just does not install Python - as pyfreeze and other utilities do).

Now setuptools is used, more usually, not to create installable for Windows - and yes - to put your project, once tested and fulfilling some quality requirements, straight into Pypi - the "Python Package Index". From there, anyone with Python and Pip (or easy_install) installed will be able to install your project simply by typing: "pip install" (and, yes, this installs the project I and the libraries it depends on). For Python programmers and users it turns out to be more practical than having an installer on some web site - you do not have to find the site, download the file, and run it - just enter the command. (And also your project becomes part of the list of projects that may be requirements of others.)

For the lay public to install, for example, a game made with Pygame, the form with Windows installer is certainly more convenient.

The setuptools documentation is really worth studying if you want to distribute your projects to the general public, end users or even the Python developer community. Start at the link: link

    
19.06.2015 / 23:01
0

A way to distribute packages in Python very similar to what java does with .jar files are Eggs

a>. This way you can run your program with:

$ python program.egg

Without worrying about dependencies, they can be bundled together with your program. I recommend looking for a read on how to create eggs .

    
23.06.2015 / 03:31