PyInstaller with Anaconda Environment Not Packaging Pip Modules - python

So, I'm running PyInstaller according to the Kivy documentation in a dedicated Conda environment.
Only one module wasn't available through Anaconda, so I had to download it via Pip. Once my .spec file packages the .exe, running it in the terminal throws a ModuleNotFoundError for only that Pip-installed module. I didn't see a place in the .spec file to include just that module, either.
Is there a way to forcibly include the module (plus any of its dependencies) into a .spec file, or is there a way to port a Pip-installed module directly to the Conda environment so that PyInstaller can spot it during packaging?

In my case, the easiest solution was just to take the module's code base and load it directly into the project.

Related

How to run a script dependency based python packages on a pendrive?

So, am working on making one of my python apps portable. (i.e.) Being capable of running off a pendrive without needing to install anything else on the user's computer.
For this I installed Python Version 3.9.8 onto my pendrive and wrote a bash script that calls
relativePathToPythonDirectoryInPendrive/python "relativePathToMyApp/myApp.py"
Unfortunately I have CairoSVG as one of my dependencies and when I installed the package via pip as follows,
relativePathToPythonDirectoryInPendrive/python -m pip install CairoSVG
At the end of installation, I get the following message :
WARNING: The script cairosvg.exe is installed in 'E:\Pendrive\PythonPortable\Scripts' which is not on PATH.
Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.
It seems that upon installing the CairoSVG package, a dependency cairosvg.exe is automatically added to the Scripts/ directory of python installed in my pendrive.
Since am calling python relatively and I have not intended on the user navigating to the Scripts/ folder to add to path in his/her computer, How to resolve the following Module Not Found error that arises on running the code :
ModuleNotFoundError: No module named 'cairo'
Thanks in advance !!!

Importing custom modules (.py files) into virtual environment

I created different virtual environments due to different dependencies requirements, one of which is running Python 2.7. I have three .py modules included in a folder, that folder is in the same directory as all my scripts. However, when I try import those three .py modules I got an error "ImportError: DLL load failed: The specified module could not be found.". I suspect that it is due to the Python Interpreter in VSCode being pointed towards my Python 2.7 virtual environment in which these three .py modules do not exist. My questions are :
How can I "install" these three modules into my virtual environment ?
Is there a quick way to install these three modules into all virtual environments ?
Thank you for your help.
You can create a setup.py, then install this folder as a module by pip
pip install -e /path/to/folder
See more at https://packaging.python.org/tutorials/packaging-projects/

How to make pyinstaller not use anaconda and build a small-size exe file

I have been trying to build .exe file using pyinstaller in windows 10. It worked, but the size of the exe file is ~212 MB, even by using a venv (as in here). I thought it might be because I am using python by anaconda!
Then I installed a separate version of Python so not to use anaconda! But it did not work (still large file).
Then I uninstalled anaconda to test it. Pyinstaller is still trying to access Python in 'C:\Program Files\anaconda3\python.exe' (this error: No Python at 'C:\Program Files\anaconda3\python.exe'). However I have removed all path to anaconda. Probably it has always tried to reach anaconda, and this is why I haven't been successful to build a small size .exe file.
How can I clearly indicate paths for pyinstaller and python?
Finally, after a lot of researching, could solve my problem:
Uninstalled all pythons and anaconda from my PC
Removed all Path from the system variables
Restarted the windows
Installed a fresh Python from its website
Installed Pyinstaller using pip install pyinstaller
Tested my .py code in cmd. It showed me all the packages that are missing.
Installed all required packages by using pip install name-of-package
Ran final command by pyinstaller -F -w --clean file.py
(Optional) Install Anaconda if you need (don't add Anaconda Python as the default python. Also don't add its path to the system variables).
Note: You can build virtualenv and do pyinstaller in them.
My previous tries which used anaconda resulted in file of 212 MB in size. This process generated a .exe file of size 27 MB (Importing only pandas module).
I ran into a similar problem and found PyCharms virtualenv manager very helpful. https://www.jetbrains.com/help/pycharm/creating-virtual-environment.html
This just necessitated downloading python from python.org and linking the virtual environment to this interpreter, rather than the conda interpreter (otherwise it will throw strange SSL errors).
This seems to allow neat parallel use of conda and virtualenv.

Spyder - python - install external packages

I have just started to use python (within Windows, 64bit) - and I have a basic question on how to install external packages within the anaconda / spyder environment. I understand that for most packages one can simply use “conda install bunnies”. However, certain packages are not in the anaconda repository, and might have be installed externally (e.g. from github). For those packages, in order to have spyder to recognize this package – does one only in addition have to update the PYTHONPATH manager in Spyder to include the directory (e.g. c:\users\bunnies) in which one has downloaded this package? Or should one take additional steps / is there a faster way?
You have several options to use packages that are not (yet) available via conda install:
1.) If the respective package is on PyPi you can build it as described in the manual.
2.) If building from scratch doesn't work and the package is on PyPi you can also try an installation via pip. Not that you have to use the pip in your Anaconda distribution and not the one of your systems Python installation.
3.) If you want to include external packages or local folders that contain Python-scripts you can do the following.
3.1.) Use the sys module and append the required package/folder to the path:
import sys
sys.path.append(r'/path/to/my/package')
3.2) Or put the modules into into site-packages, i.e. the directory $HOME/path/to/anaconda/lib/pythonX.X/site-packages which is always on sys.path. (Source)
3.3) Or add a .pth file to the directory $HOME/path/to/anaconda/lib/pythonX.X/site-packages. This can be named anything (it just must end with .pth). A .pth file is just a newline-separated listing of the full path-names of directories that will be added to your path on Python startup. (Source)
Good luck!

Install custom modules in a python virtual enviroment

I am doing some pylons work in a virtual python enviorment, I want to use MySQL with SQLalchemy but I can't install the MySQLdb module on my virtual enviorment, I can't use easyinstall because I am using a version that was compiled for python 2.6 in a .exe format, I tried running the install from inside the virtual enviorment but that did not work, any sugestions?
Ok Got it all figured out, After I installed the module on my normal python 2.6 install I went into my Python26 folder and low and behold I happened to find a file called MySQL-python-wininst which happened to be a list of all of the installed module files. Basicly it was two folders called MySQLdb and another called MySQL_python-1.2.2-py2.6.egg-info as well as three other files: _mysql.pyd, _mysql_exceptions.py, _mysql_exceptions.pyc. So I went into the folder where they were located (Python26/Lib/site-packages) and copied them to virtualenv's site-packages folder (env/Lib/site-packages) and the module was fully functional!
Note: All paths are the defaults

Categories

Resources