PyInstaller error loading Python DLL when running executable on another machine - python

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!

Related

Force Anaconda to use Python 3.4 on Windows 7

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.

Ensure pyinstaller run with Python 2.7

I've a Python project, run it on Ubuntu 18.04 server machine (in VBox). I've created 2 venvs:
* virtualenv -p /usr/bin/python2.7 venv27
* virtualenv -p /usr/bin/python3.6 venv36
Start venv27 with command:
source path/to/my/venv/python/venvs/venv27/bin/activate
After venv starts to run I've installed PyInstaller with:
pip install pyinstaller
Generation process was sucesfully done, but during the generation process I've seen this message:
46 INFO: Python: 3.6.8
Does it means that PyInstaller run with Python 3.6 however I run PyInstaller in venv where python version is 2.7?
I would like just be ensure that my compressed python code use python 2.7?
Thanks for your help and answer!
I've delete all created venvs and start it again. Here is the results:
Activate the new venv27:
Installed again PyInstaller:
...and now the message was:
Currently I've not created venv36 only venv27, so probably problem could be, but I am not sure that venv36 was active, but I didn't know that.
Thank you Gantemens for your help. My last question is: how can I accept your answer/suggestion because it looks like both comment were right.

Running pipenv environment via $PATH symlink to executable .py file

I have a Python app that I use locally that needs to be launched via pipenv run python3 appname.py in order to load virtual environment with installed dependencies. This is all on macOS.
What I want to achieve is to be able to run this app from anywhere with $ appname [args].
So what I did was:
add #!/usr/bin/env pipenv run python3 to appname.py;
make that file executable with chmod +x appname.py;
make symlink with ln -s /path/to/appname.py ~/.bin/appname;
put ~/.bin on my $PATH.
Now when I launch $ appname, pipenv creates a new virtual environment in the ~/.bin folder and complains about missing dependencies, all instead of following through into the actual location of the script.
Is there a way to overcome this? Or maybe a better way to achieve what I want?
For my purposes a more sensible thing to do was freezing my code by packaging it (along with all dependencies) into an executable with pyinstaller.
What I did was:
Installed pyinstaller as dev dependency with pipenv install --dev pyinstaller;
Launched pipenv shell in the project directory;
Packaged the app with pyinstaller --onefile appname.py;
Moved the resulting self-containing [project path]/dist/appname executable into my ~/.bin directory.
There were some unrelated issues to overcome, but otherwise worked perfectly for me.

Pyinstaller command not found (MacOS)

I've been trying to use PyInstaller on my program, scratch_1.py. The PyCharm project folder is called "idigen", which is saved in my desktop. So, I changed the director like so:
cd /Users/joelsaarinen/Desktop/idigen
then, moved on to use pyinstaller, and I get this error:
pyinstaller scratch_1.py
-bash: pyinstaller: command not found
I'm confused because when I use:
pip show pyinstaller
to verify that I have pyinstaller installed, it returns a positive result.
Is there an additional command I should be putting in when using Pyinstaller on one of my files? Might this be an issue with this specific program or the operating system in general? Thanks in advance.
This is a common problem due to the fact that you might install a different version of python and keep using an old version that is preinstalled in the machine. Here is the best solution.
First, check the version of the python that you installed. In my case, i installed python 3.5 and the machine had python2.7. If you run python on the terminal, most likely the preinstalled one is the one that will run.
Second, check the directory of your desired python version. watch -a python3 is the command to run to see your directory.
Third, set the directory as the main one to run your python commands.
alias python=/usr/local/bin/python3 does the whole trick
Lastly, reinstall pip. Download the get-pip.py file and run sudo /usr/local/bin/python3 get-pip.py * I used the path to show the reason we updated the alias*
Now you can run pyinstaller without problems
pyinstaller appears to have installed correctly, but the command is not available on PATH. You need to locate where the executable was placed.`below to find executables
set | grep pyinstaller
now modify path by this
export PATH=some_path:another_path
launchctl setenv PATH $PATH
I just downloaded the source code of pyInstaller from official website, put it where I can find it and wrote a script which launches pyinstaller.py from that folder.
For some reason, pyinstaller.py is missing in the pyInstaller installation downloaded via pip.
I had the same issue on MacOS with Developer Tools 11.4 and found two ways to start pyinstaller:
alt 1: path based solution
$ pip3 show -f pyinstaller|grep pyinstaller
will find pyinstaller in a bin path:
../../../../usr/local/bin/pyinstaller
...
So you can use one of the set-the-path-or-an-alias approaches or call via fully qualified path.
alt 2: call via python module
$ pip3 show -f pyinstaller|grep __init__
will get you a hint on how pyinstaller is defined as a module:
PyInstaller/__init__.py
...
With that capitalization, it's possible to call pyinstaller as a module with the following:
$ python3 -m PyInstaller --version
4.2
I'm using the latter now.

virtual environment can't start python -- "No such file or directory"

I have created a venv using Pycharm. On the PyCharm terminal, everything works fine -- I can activate the venv, and start python normally.
When I exit PyCharm and go to the normal linux terminal, it doesn't work.
First I go to my directory:
$ cd /home/me/PycharmProjects/virtualenvs/my_project/bin/
Then I activate the venv
$ source ./activate
I check my python file
(my_project) $ which python
/home/me/PycharmProjects/virtualenvs/my_project/bin/python
But when I try to invoke python, it fails
$ python
/home/me/PycharmProjects/virtualenvs/my_project/bin/python: No such file or directory
Am I missing something or is this a problem with PyCharm? This is on Linux Mint, recently installed with minimal changes.

Categories

Resources