pipenv and pyinstaller not packaging dependencies - python

I'm fairly new to python I'm trying to create an executable of my python project that is run in pipenv. However, when I try and compile and run the code using pyinstaller it can't find any dependencies since they aren't installed globally. I don't want to install them globally, this is supposed to be a deployable build that shouldn't require any setup beyond just the exe.
Am I missing something? Is this even the right way to go?
I can run the project easily like so:
pipenv run python iot.py
It has a dependency:
from AWSIoTPythonSDK.MQTTLib import AWSIoTMQTTClient
And I try and compile the project like so:
pipenv run pyinstaller --onefile iot.py
It creates an executable that fails to find imported modules.
Traceback (most recent call last):
File "iot.py", line 18, in <module>
ImportError: No module named AWSIoTPythonSDK.MQTTLib
[48823] Failed to execute script iot
Am I just so off in my attempt or is there just a simple missing link?
Thanks for any help.

This is because you installed pyinstaller globally.
Use pipenv install -d pyinstaller before packing.

I found that pyinstaller won't package dependencies inside the pipenv.
If I install the dependencies globally I can ship the exe.
For now, I'll make a build machine that handles downloading dependencies and building the exe.

You can tell pyinstaller to look in the virtual env created by pipenv when searching for the required modules.
$ pipenv --venv
path\to\.virtualenvs\project
$ pipenv run pyinstaller --paths path\to\.virtualenvs\project project.py

Related

pyinstaller downloaded using pip not working after installation

Screenshot of error
I'm trying to install a module called pyinstaller from pip to make .py files into an executable, but can't run it from command prompt. Any ideas as to why it doesn't work or workarounds with other applications that serve the same purpose?
try changing directory to where python location is and try installing again
i.e C:\Users--------------------\AppData\Local\Programs\Python\Python39> pip install pyinstaller

PyInstaller on cygwin

I need to create an .exe file from a .py file on cygwin. Since py2exe doesn't seem to work there, I tried PyInstaller. However I have a problem installing it. pip install pyinstaller returns this message:
ERROR: Failed compiling the bootloader. Please compile manually and rerun setup.py
So I tried to follow this guide: https://pyinstaller.readthedocs.io/en/latest/bootloader-building.html and install it manually. But when I run pip install https://github.com/pyinstaller/pyinstaller/archive/develop.tar.gz the folder that I get for PyInstaller is not https://github.com/pyinstaller/pyinstaller but this one: https://github.com/pyinstaller/pyinstaller/tree/develop/PyInstaller in which there are no waf files and I can't run python ./waf all.
So I downloaded the needed folder from github manually and then python ./waf all succeded. However, I still can't not use PyInstaller since I get this error when trying to call it from command line:
ModuleNotFoundError: No module named 'PyInstaller.__main__'
And I have no clue how to fix it. What should I do to get PyInstaller working or maybe I need to to use some other module that works with cygwin?

pyinstaller on virtualenvs, No module named Import Error

I am trying to create virtualenvs for my script. When I use pyinstaller without virtualenvs (just sudo pyinstaller myscript.spec) everything works fine. After that I activate virtualenvs and do same thing (pyinstaller myscript.spec) . When I try to execute this two files the standart one (first one) works but the one that I create with virtualenvs gives ImportError: No module named 'sip'. I did not use sip in my script and did not import it anywhere. I do pip3 install sip and compile script again but it did not change anything. What is this error and how can I fix it?
Try sudo apt-get install python-sip to install Ubuntu's version

Conda Cython Build PYD/SO Files

I have built a module using "conda build packagename".
However, the built module ends up in "\Anaconda\conda-bld\work".
The module can only be imported (using "import packagename")if I cd into this directory, then run Python. I have tried placing the files in "\Anaconda\conda-bld\work" in "\Anaconda\Lib\site-packages", however I am not able to import the module from any directory; I must be in "\Anaconda\Lib\site-packages".
Is the only solution to put the .PYD file/ .SO file next to the executable Python file or is there a way to let Python know there is a new module installed?
Thank you for your help.
In the conda build script, you need to install the files, not just build them. For Python, this typically means running python setup.py install in the build.sh, and including python in your build dependencies so that the python will install into the build environment.

Setup tools install command differences

What are the differences between the below commands
python setup.py install develop
Doesn't work for me error No such file or directory: 'build/bdist.macosx-10.7-intel/egg/test-easy-install-37886.pth'
python setup.py develop
Works for me appears to make an .egg link file
python setup.py install
Works for me appears to make a .egg file which in .zip file format
Develop is a setuptools / distribute feature that allows you to add a project
to your Python environment without installing it - so you can continue
its "development"
In other words, when you call "python setup.py develop", setuptools will
compile the metadata and hook your project into Python's site-package,
but the packages and modules that will be used are the one in the
directory where you've run that command.
This is useful to continue working on your code and testing it without
having to run "python setup.py install" on every run
With develop, Python 'pseudo-installs' a package by running the setup.py script instead of install. The difference is a modification of the environment (it doesn't with develop), so a package can be imported from it's current location instead of a site-package directory. The advantage of this is you can develop packages that are being used by other packages, and you can modify source code in place with develop.
As far as "setup.py install develop", I've never seen anyone use that before, sorry.
source
source
source
python setup.py install develop
Is a wrong command.
When you use develop you use the current code when you run your application.
When you useĀ install and then modify you code, your modifications will not be taken in account while running your app. until you rerun install or develop.

Categories

Resources