Cannot locate python module: KV Language, PyInstaller - python

I have an application developed in Kivy which works fine when I execute using a python interpreter. The problem happens when I try to execute after creating an executable using pyinstaller. The .kv file is unable to locate the python modules that it needs. I believe this has something to do with root path configuration of the KV Language but I couldn't find anything to resolve it. "config.py" is the harness/entry file that pyinstaller analyzes. The error occurs in "kv/root_screen.kv" which imports the respective python modules present in "baseclass" folder. Find the screenshot of the error and directory structure below. I have tried executing the files from multiple directories to no effect.

I had the same problem, for me the solution was to fully uninstall all your versions of Python, NOT your code editors, but the Python files.
Usually located in:
C:\Users\YOUR PC NAME\AppData\Local\Programs\Python\Python311
After that go to the official python website:
https://www.python.org/downloads/
And download your preferred version.
In the install click: Add Python... to Path:
https://i.stack.imgur.com/YXYmE.png
Then install your modules using PIP.

Related

Packing python scripts into .exe file while keeping imported modules

I have a python script I want to pack into .exe file for the ease of use. The python script makes extensive use of Tkinter module for nice GUI. I've packed it first into .exe using pyinstaller and the guide outlied here - https://datatofish.com/executable-pyinstaller/
I have two problems. First is that my script makes use of FlowCal module, which doesn't come with Python's pyinstaller (I've made script using Spyder, and I'm using Python 3.8. to compile using pyinstaller) - so I installed FlowCal with pip install FlowCal so Python gets it too (I think that's how it works? Not too sure). But then FlowCal is dependent on various sklearn modules, and it would be a headache to install modules, compile to exe, then check if it works over and over. Is there a way that ALL modules script uses (and ALL modules that imported modules use) are compiled into the script?
Second problem is that alongside GUI I get another window. Picture included. How do I remove that window?
Another thing you can do without any hassle is using auto-py-to-exe. This will generate .exe from .py with writing command, just clicking some buttons in a GUI. For this, you have to give the command: pip install auto-py-to-exe in command prompt or PowerShell, whatever you like most. After successfully installing auto-py-to-exe, give the command auto-py-to-exe in your command prompt. Then give the necessary informations, and get your generated executable file!
Add the missing modules to the hiddenimports
hiddenimports=['sklearn.neighbors.typedefs','sklearn.neighbors.quad_tree','sklearn.tree._utils']
Or use it when you create the exe in cmd as
--hidden-import=modulename

Python Selenium GUI to an executable

I have never made an executable application before but from what I have read its pretty easy, using py2exe to generate the exe.
But I have a GUI that uses Selenium to scrape data from a backend (No I can not use API calls). How do I add chromedriver to the executable? Also, would all the imports go along when using a compiler?
When you compile a .py file into an .exe (from my personal experience) all of the imports are included.
I would personally suggest using pyinstaller. I had quite a few problems using py2exe and as a beginner I found pyinstaller much more user-friendly and easier to troubleshoot.
As compiling a file does not alter the .py file, I would suggest getting it to a fully working state and trying it. If it doesn't appear to work or if some of the imports are lost, we can troubleshoot with the error code.
You can also use cx_Freeze to create an executable from your python script.
You can install cx_Freeze by issuing the command
python -m pip install cx_Freeze --upgrade
in a cmd prompt / terminal.
As far as tkinter is concerned, you'll find a working example of how to freeze a tkinter-based application with the current version of cx_Freeze in this answer. In the setup.py script you find there, you need to replace the name of the Executable by the name of your main script. Place this setup.pyin the same directory than your main script and run
python setup.py build
from a cmd prompt / terminal.
As far as chromedriver is concerned, I've no experience, if you choose this approach and still have problems, please add the exact error message and a Minimal, Complete, and Verifiable example to your question.

Why doesn't pynsist shortcut start python script?

I recently tried to build an installer of a python application built with PyQt5. Unfortunately, after getting the installer via .cfg file and installing it on another computer the script does not start by clicking the shortcut in the (Windows) start menu.
When trying to start the Python-script directly by double-clicking it in the according folder of the installation, Python keeps crashing since PyQt5 is not installed on the computer (although it can be found in the installation-folder). In case I manually install the package via pip install PyQt5 it works when clicking on the script, but not when using the shortcut in the menu.
I suppose this could have to do with the automatically generated file path of the shortcut, but I could not find a solution how to fix it when building the installer. I used script instead of entry_point for it - could it be that this produces my problem?
Thank you in advance!
Here is what my .cfg script looks like:
[Application]
name=sample_name
version=V0.1
publisher=sample_publisher
script=C:\path to Python script\launch_script.pyw
icon=sample_icon.ico
[Python]
version=3.6.3
[Include]
pypi_wheels=PyQt5==5.10
files=folder_with_additional_scripts
[Build]
directory=build\

Compiling a non-standard module into an executable file with PyInstaller

Background: I have had success in the past installing and using Pyinstaller to transform my python projects into one-file executables. I don't think it is an issue with my source code or pyinstaller files.
Problem: I used a free, open-source library/module called easygui imported into my source code to build an application. The application works perfectly run natively or through the Python IDE. I am pretty sure the problem is that Pyinstaller is not finding the EasyGUI module to import (it automatically includes and compiles any libraries you import in the script).
Actions: My python folder is not in the C:\ drive, it is in the E:\ drive. I'm able to access the pyinstaller path in "E:\program files\python" but it is not reading the easygui library, I don't think. I installed pyinstaller and easygui using pip.
Reading a LOT of pyinstaller's documentation i tried to run it to include a paths dir like:
E:\Program Files Hard Disk\Python\Scripts>pyinstaller --paths
DIR "E:\Program Files Hard Disk\Python" --onefile "E:\Program Files\Python"
It does output the single executable in the build file but does not launch correctly. From what I can see in the console window the brief moment it's up, it looks like an easygui issue. Here is the result of attempting to launch the executable from the command-line:
Here is the compiling in the command window:
Please help

Getting Enthought Python Distribution to Cooperate with COPASI and libsbml

I've been using the Enthought Python Distribution (the Academic version) for some time now, but have been trying to install some extra packages for a project, and running into problems born of my relative inexperience with the command line.
These are:
COPASI
libSBML
StochPy
The last one went well, a simple python setup.py install and everything seems to be running fine. But neither COPASI nor libSBML seem to be working.
Importing either one of them is netting "ImportError: No module named COPASI/libsbml".
I installed libSBML according to the directions here.And used this suggested workaround to get it working with Enthought, to no avail. For COPASI, I installed COPASI as directed, and followed the following directions for the Python bindings:
Once you downloaded the binary package for the Java bindings you have to unpack it. It will be unpacked to a directory called copasi_python. This directory contains the native library, a python file, a documentation file and the license file. It also contains a directory called unittests with lots of unittests that can be used to check if the bindings are working.
To run the unittests, you first have to set the PYTHONPATH environment variable to the directory where the native library and the COPASI.py file are located. Once you changed into the unittests directory you find a file called runTests.py which runs all the unittests in the directory.
My edited .bash_profile file now looks like this:
export PATH="/Library/Frameworks/EPD64.framework/Versions/Current/bin:${PATH}"
export PYTHONPATH=/usr/local/lib/python2.7/site-packages
export PYTHONPATH=/Applications/COPASI/copasi35_python27_macosx107_x64:$PYTHONPATH
The first line is to make EPD the default python interpreter, the second is the result of the suggested workaround above, and the third is per the instructions for COPASI. Any idea what I'm doing wrong?

Categories

Resources