Force Anaconda to use Python 3.4 on Windows 7 - python

I'm trying to compile a Python script to an .exe using PyInstaller. I am compiling a 32-bit application which must use Python 3.4. Python 3.4 is only compatible with PyInstaller 3.4 or older, so I am using PyInstaller v3.3.1. I am using an Anaconda environment.
I would activate my Virtual Environment, which says it is Python version 3.4.5. Then I would run
pyinstaller --onefile script.py. For some reason, my virtual environment then decides to use Python 3.6. I am wondering how I can force my script to use Python 3.4.
I have tried py -3.4 -m pyinstaller ...., but it says py is not a recognized command. I then tried to add it to Path, but it still did not work. Please see below for screen shots.
and

First, use the conda command to uninstall PyInstaller:
conda uninstall pyinstaller
Next, activate your virtual environment, run
python --version
to ensure you're using Python 3.4, then run
python -m pip install pyinstaller==3.3.1
to install that version of PyInstaller to your virtualenv. You should then be able to run
pyinstaller --onefile pyopc_da_connector.py
or whatever the name of the file is, and you should be all set.

Related

PyInstaller error loading Python DLL when running executable on another machine

I'm trying to run a pyinstaller-built executable on another machine. The error I see is Error loading Python DLL 'C:\Users\User\AppData\Local\Temp\_MEI70722\python39.dll
I built the program like this, I also added -F to make sure the executable is standalone:
py -m PyInstaller script.py -F
I tried adding --add-binary and --add-data options with the path to python39.dll, but that didn't help.
The program is built on Windows 10 x64, the machine I'm trying to run the program on is Windows 7 x64. Even with such a difference and the fact that Python 3.9 is not for Windows 7, I really doubt this is the reason, otherwise I would expect another error.
What am I doing wrong?
Ok so here's solution that worked for me:
Install a Windows7-compatible version of python3. I did this from the Windows Store, which made it accessible in my command line as "python3."
Set up a virtual environment with your downgraded version of python. On command line, that's
...> python3 -m venv my_env
In command line, navigate to your newly created environment directory, and use pip to re-install pyinstaller in your new environment:
...> cd my_env
...\my_env> pip install pyinstaller
From command line in my_env, use pyinstaller to compile your code. You should probably move script.py into your my_env directory.
...\my_env> pyinstaller script.py -F
I was able to copy the standalone script created in \my_env onto a Windows 7 machine and run it successfully. Hope this helps!

Python path configuration for pyinstaller

I am having issues with getting pyinstaller version 3.6 to work to make my application executable. The crux of my problem is that pyinstaller is not compatible with python 3.8, but when I check python --version on my terminal it confirms I have python 3.7. However, when I check my pip path it gives me pip 20.1.1 from /Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/pip (python 3.8). Also, I am currently using VScode as my editor, and when I check sys.version_info in my app script it gives me version 3.8 as well. I tried creating a virtual environment in new file, double checking the package.json with 3.7, but when I run sys.version_info it still gives me 3.8 (I am still a beginner at using shell/terminal so I am confused as to why since my python version is 3.7 on my shell).
I worried about doing a complete uninstall of python and pip since I've read it could mess up the paths and cause complications repairing. How can I change the pip path to python 3.7 or have my script run 3.7 so that I can use pyinstaller on my macOS?

Create a virtual environment with python version 2.7 with existing version as 3.7

I want to create a virtual environment with python version 2.7 on windows, however, after installing virtualenv and running python 2.7 -m venv project
I am receiving an error RuntimeError: failed to find interpreter for Builtin discover of python_spec='2.7'
I have downloaded the 2.7 version of python as well, what am I missing?
venv is a package that was only introduced from python 3.3 and above.
( https://docs.python.org/3/library/venv.html )
I never used it.
You might use virtualenv, that exists also for python 2.7. but must be installed with following command (but you did this probably already)
py -2.7 -m pip install virtualenv
You then type
py -2.7 -m virtualenv project_dir
if none of above works, then please type
py -2.7 -m pip freeze and post the output.
You can also type
py -2.7 -c "import sys ; print(sys.executable, sys.version_info)"
To see what python 2.7 version you have exactly installed.
The difference between py.exe and python.exe:
On windows py.exe is the python launcher, that tries to keep track of all installed python versions and of potentially activated virtualenvs and launches the one you want.
python will try to find the python executable in the search path.
and it would yield the first python in the path.
py is the windows python launcher which will locate the python executables with help of environment variables and the registry and which allows with the -version (e.g. -2.7) switch to select which version of python you want to call.
( Documentation for the python launcher on windows:
https://docs.python.org/3/using/windows.html#from-the-command-line )

Error loading Python lib with PyInstaller on MacOS

I am trying to package some python into an executable on MacOS (10.14.5). I am able to create the executable, but executing the resulting dist/hello_world executable gives the following error:
[55240] Error loading Python lib '/var/folders/yh/6_6mb2y96kg0gnb_nh9r2zrr0000gp/T/_MEIwUMw4X/Python': dlopen: dlopen(/var/folders/yh/6_6mb2y96kg0gnb_nh9r2zrr0000gp/T/_MEIwUMw4X/Python, 10): no suitable image found. Did find:
/var/folders/yh/6_6mb2y96kg0gnb_nh9r2zrr0000gp/T/_MEIwUMw4X/Python: code signature invalid for '/var/folders/yh/6_6mb2y96kg0gnb_nh9r2zrr0000gp/T/_MEIwUMw4X/Python'
My machine is running Python 3.7.7 installed from using the Mac installer downloaded from https://www.python.org/
For now, the script I am trying to package only contains print('hello world!') and the packaging command I am using is pyinstaller -F hello_world.py
I had success using pyenv and installing the specific version of python with the enable framework option:
env PYTHON_CONFIGURE_OPTS="--enable-framework" pyenv install 3.7.6
With this version of python (set using the command pyenv local 3.7.6 in the folder where hello_world.py is located), install pyinstaller (and any other modules you need) with pip. Then build with
pyinstaller hello_world.py --onefile --clean --windowed
which should give you a functioning dist/hello_word. As a python fledgling, I have no idea why this works as opposed to the steps in the original question. (I thought the Mac OS installer included the Python.framework by default -- I'm sure my ignorance is exposed here as this probably differs significantly from what the PYTHON_CONFIGURE_OPTS variable is doing above).
Also possible to do all this within a virtual environment (easily managed by pyenv-virtualenv).
The latest version of Pyinstaller only supports Python 2.7, 3.5–3.7. If you downgrade to Python 3.7 it will work!

How to change python version for use with pyinstaller

I am trying to convert a .py file to an exe. My file, hello.py, reads:
print "Hello, World!"
I am currently trying to use pyinstaller. However when I run the command
pyinstaller hello.py
I get the error message "tuple index out of range" which I have been told means my version of python is unsupported. In particular it would seem the situation is that pyinstaller thinks I am trying to compile python 3.6 code into an exe. But I have python 2.7 and python 3.6 installed. How do I let it know that I want it to regard the code as python 2.7 code?
Using Python3:
Make sure PyInstaller is installed in Python 3.x: pip3 freeze
PyInstaller==3.3.1
Then running the command:
/path/to/python3 -m PyInstaller your_script.py
First install Pyinstaller in your python2.7 version if not installed previously
py -2 -m pip install pyinstaller
and then go to your folder and
py -2 -m pyinstaller -F filename.py
When you need to bundle your application within one OS but for different versions of Python and support libraries – for example, a Python 3 version and a Python 2.7 version; or a supported version that uses Qt4 and a development version that uses Qt5 – we recommend you use virtualenv. With virtualenv you can maintain different combinations of Python and installed packages, and switch from one combination to another easily. (If you work only with Python 3.4 and later, python3 -m venv does the same job, see module venv.)
Use virtualenv to create as many different development environments as you need, each
with its unique combination of Python and installed packages.
Install PyInstaller in each environment.
Use PyInstaller to build your application in each environment.
The answers have devolved in "How do I tell pyinstaller which python version to use?" So, I know that this doesn't really answer the original question. However, I wasted about an hour trying to figure this out so, in the hopes that others don't have to waste an hour... To force pyinstaller to use Python 3.9 under Windows do the following.
Given Windows and Python 3.9:
python3.9 -m PyInstaller [whatever options you want]
You have to type it as PyInstaller instead of pyinstaller (i.e. note the capitalization).
python3.9 -m pyinstaller
Produces an error:
C:\Users\chris.SR\AppData\Local\Programs\Python\Python39\python.exe: No module named pyinstaller
Supposing you have python 2.x on the path under python2 you can do
python2 -m pyinstaller hello.py
I ran two a couple things.
If you uninstall python3, it works with python2.
If you have python3 installed (and it is the primary), and have pyinstaller installed in python3, it wont work (python3 pyinstaller used).
If you have python3 installed, but do not have it installed in python3 or uninstalled it (pip3 uninstall pyinstaller), pyinstaller works.
Checking the environmental variables (windows 10) PATH had python3 first. This may be the issue and may not be resolved because it is checking python3 directories first, and picks up pyinstaller for python3. pyinstaller does not check the file either (#!/usr/env/bin python2).
Unless pyinstaller puts an option relating to this issue, there may be no solution short of uninstalling pyinstaller from python3 temporarily.
note
could also use py2exe, using py2exe for python2, pyinstaller for python3

Categories

Resources