Converting .py to .exe with Anaconda - python

I made a python program using PyGame which is only available for Python 2.7 so that is my python version.
I am using Anaconda because it is easier to install modules and to use python, but the site hasn't py2exe module for 2.7.
Is there another way to convert it? Or some way to install py2exe for 2.7 in Anaconda?

How to create an executable using Anaconda 3 (specifically Anaconda Prompt) for Windows.
1 - Make sure pyinstaller is installed in your anaconda
pip install pyinstaller
2 - Move to the directory of your python script
cd C:\Users....\program.py
3 - Just type the following:
pyinstaller --onefile program.py
If everything goes well, in the folder where you have your script.py you it will be created many folders and your executable is inside folder "dist".
If my explanation is confusing go here: https://medium.com/dreamcatcher-its-blog/making-an-stand-alone-executable-from-a-python-script-using-pyinstaller-d1df9170e263

Instead of using py2exe you could try to build your executable with pyinstaller.
http://www.pyinstaller.org/downloads.html
The PyGame package is also supported with pyinstaller according to this link
https://github.com/pyinstaller/pyinstaller/wiki/Supported-Packages

Another solution is Conda Constructor.
Constructor is a tool which allows constructing an installer for a collection of conda packages. It solves needed packages using user-provided specifications, and bundles those packages. It can currently create 3 kinds of installers, which are best thought of as delivery vehicles for the bundled packages. There are shell installers, MacOS .pkg installers, and Windows .exe installers. Each of these will create an environment on the end user's system that contains the specs you provided, along with any necessary dependencies. These installers are similar to the Anaconda and Miniconda installers, and indeed constructor is used to create those installers.

Related

Importing python package from conda environment in VSCode

enter image description here
Somebody please explain why I am not able to import package in VSCode even though I can do it in terminal both in VSCode and in system
Check out https://code.visualstudio.com/docs/python/environments
VSCode uses multiple python binaries. Each one has a seperate list of installed modules and packages. By default VSCode uses a custom Anaconda binary. When you invoke the python command, you are using a system wide install of Anaconda. You need to change the binary version of python VSCode is using, to point at the system-wide install, where you installed your modules

How to make Sublime's python interpreter work when Sublime's on Windows and Python is on Ubuntu

I am running Ubuntu on Windows (I can't change it). I use Sublime Test 3 as my code editor. I have Python installed on Ubuntu and I know the path to it from within Windows. Sublime's Python interpreter is not working when I run it. I would like to be able to do both of the following:
a) Run basic Python commands in Sublime Text 3 on Windows using Python installed in Ubuntu folders
b) Run Python modules in Sublime Text 3 on Windows using modules installed in Ubuntu folders
I have already tried adding the path to Python's Ubuntu folders to the PATH environment variable (for user, not for system). I didn't work.
Then I installed Anaconda Python distribution on Windows, and added its path to the PATH variable (for user again). It did work. However, it means having to maintain two Pythons - one on Windows and one on Ubuntu, which defeats the purpose of my search. Also, I only managed to make it work for basic Python, and not for libraries. Adding PYTHONPATH variable with the path to Anaconda's modules on Windows broke the import of numpy and other libraries.
Just to clarify, I do not use Anaconda distribution, I was just trying all I could.
Do you need your Sublime3 in Windows?
You can install it in your Ubuntu OS instead.

python 3.4.3 64bit a program required for this install could not be run

Trying to install Python 3.4.3 64-Bit and it gives me the following error:
'There is a problem with this Windows Installer package. A program required for this install to complete could not be run. Contact your support or package vendor'
I have no bloody idea what this means so please help. Thanks in advance
I'm the admin on my computer and have all permissions
My windows is 64bit and is Windows 8.1
I had the same phenomenon occur when trying to clean up (uninstall various versions of Python and perform a clean install of 3.4.3) on my Windows 7 64-bit laptop. Unfortunately, I cannot tell you what "program required for this install to complete could not be run". Repeated attempts to "install for all users" produced the same "could not be run" (followed by a roll back of the install). Just before getting out Orca and diving into the innards of the MSI file, I attempted an "install just for me", and the install completed. I am, in fact, the only (human) user of this computer. There is another user account that was created during a cygwin setup, and access to some aspect of that user's profile/resources may have been the issue. If you are installing Python for your own use - and not as a "platform-wide" resource for other users as well - you might try installing "just for me".
For me the problem was that I had an older version of Python installed, that the MSI could not un-install. I had to manually remove it first.
This is how I resolved the problem on my Windows7 machine...
Open a command prompt and navigate to the location of the python.exe. (For me this was C:\Python34.)
Execute this command
python3 -B -m ensurepip._uninstall
Close the command prompt.
Using the python MSI file for the version of Python I had previously installed (yes, I went to the Python archive and downloaded the MSI for the old version), install Python again, but without the "pip" package. (Not sure if this is necessary, but it worked for me.)
Using the same Python MSI file, uninstall Python completely.
Using another MSI, for the version of Python you wish to install, you should now be able to perform a "clean" install.
I got the same error while uninstalling the python file from the control panel. It prompts
There is a problem with this Windows Installer package. A program required for this install to complete could not be run. Contact your support or package vendor
I have solved this problem by installing the specific python-<version>.amd64.msi.
I then executed the MSI file. It asks for Change, repair, remove. First, click on Change radio button and complete execution. Later you can come to control panel and repair or uninstall the python file.
I had the same symptoms as OP. In my case, i had two separate installs, one of 2.7 and one of 3.4.3 and when i checked the PATH variable, there were 2 lines about PYTHONPATH pointing to the 2.7 version.
I removed the lines and then the repair funciton of the MSI did work. I uninstalled both versions and proceeded to reinstall.
Done :)
On a Win7 box:
Startup/ right click on Computer / Properties / Advanced system settings / Environment variables then check both sub-windows for paths related to python.
I had just the exact problem. But in mine case i've additionally removed the c:\python27 and c:\python36 directories and associated installers got stuck around Install/Uninstall and could not completely repair the installation (the /Scripts subdirectory has been missed and the python.exe reported an error about missed encodings module).
But i've found a solution for myself. Seems somehow the PYTHONHOME and PYTHONPATH environment variables (and may be PATH too) has been interfering with the Python installation process. But because i could not run Uninstall from the Windows Uninstall list in the Control Panel, then i did this:
Cleanup the PATH environment variable from all python path occurrences.
Remove PYTHONHOME and PYTHONPATH environment variables.
Restart Windows Explorer if environment variables (console command set PY must return the empty list) is not updated.
Run repair from (!) the python-3.4.4*.exe/python-2.7.11*.exe executables (download it if not done yet). Icons in the Windows Uninstall list in the Control Panel will reset into the original state for a repaired python installation.
Run the Uninstall from the same executables or from Windows Uninstall list in the Control Panel.
And it did the trick!
If you still needs the both versions of the python installation, then try install the older versions before the new versions. Seems it's important too.
Poking around, there is a temp file saying:
Error 1721. There is a problem with this Windows Installer package. A
program required for this install to complete could not be run.
Contact your support personnel or package vendor. Action: UpdatePip,
location: C:\Programs\PY272\python.exe, command: -m ensurepip -U
--default-pip
=== Logging stopped: 6/12/2015 13:26:17 ===
OK, so the missing "Voldemort" file (that which shall not be mentioned) is the ensurepip package. There is documentation for ensurepip at https://docs.python.org/2/library/ensurepip.html. I am still on 2.7, but it looks like this is a shared problem with Py 3.
The documentation says the ensurepip package is new in 2.7.9. My solution: install a version prior to 2.7.9 and then upgrade the files myself from an existing install. Done.

Using py2exe in a virtualenv

I have a Python script I developed within a virtualenv on Windows (Python 2.7).
I would now like to compile it into a single EXE using Py2exe.
I've read and read the docs and stackoverflow, and yet I can't find a simple answer: How do I do this? I tried just installing py2exe (via the downloadable installer), but of course that doesn't work because it uses the system-level python, which doesn't have the dependencies for my script installed. It needs to use the virtualenv - but there doesn't seem to be such an option.
I did manage to get bbfreeze to work, but it outputs a dist folder crammed with files, and I just want a simple EXE file (one file) for my simple script, and I understand Py2Exe can do this.
tl;dr: How do I run Py2Exe within the context of a virtualenv so it correctly imports dependencies?
You can do that this way:
Activate your virtualenv and then ...
easy_install py2exe-0.6.9.win32-py2.7.exe
Installing py2exe into your virtual env should be straightforward. You'll need Visual Studio 2008, the express version should work. Launch a 2008 Command Prompt and Activate your virtual env. Change into the directory that contains the py2exe source and run python setup.py install. You can verify that py2exe is in the correct environment by attempting to import it from an interactive shell. I tested myself earlier today (had to install virtualenv). It works exactly as expected.

Modify Python Path for Python3 only

I am developing in both Python 3 and Python 2.6, and have both versions installed. With Python 3, however, the path to lots of the good modules (time, math, ...) is not part of my Python path. I can add the directory to the path, but it's tedious.
Is there a way to permanently modify the path for my Python 3 installation without affecting Python 2?
Create virtual environment: http://pypi.python.org/pypi/virtualenv/
Install packages you want in virtual environment.
If you can't import time, math modules that are in stdlib then your installation of Python 3 is broken.
When you run python setup.py install the files are installed in correct place for current python executable be it a system python or python from a virtualenv environment. The same goes for pip.
You don't need to modify any paths, just use an appropriate executables.

Categories