Error: Unable to import package 'kivy_gradient.Gradient', while trying to run the exe file using pyinstaller - windows

I imported #:import Gradient kivy_gradient.Gradient in my .kv file. The app is working fine without any error.
When I try to convert the file to exe using pyinstaller using : pyinstaller --hidden-import kivy_gradient.Gradient main.py -w. Then modifying my specs file as:
from kivy_deps import sdl2, glew
a.datas += [('Code\filename.kv','location\filename.kv','DATA')]
Tree('folder_location')
*[Tree(p) for p in (sdl2.dep_bins + glew.dep_bins)]
And finally building my exe file using pyinstaller main.spec -y command.
When I try to run the exe file it show the error: Unable to import package 'kivy_gradient.Gradient'. Please help me, I have been struggling for long.

Related

shiboken2 & PySide2 issues

I get this error when trying to run a PyQt5 Application, I keep getting it and I think it's when I use pyuic5 to export code from QT Designer and then try to run it.
from .shiboken2 import *
ImportError: DLL load failed: The specified procedure could not be found.
I have used pip freeze to find the versions of shiboken2 and pyside2 and they are both the same version.
I installed Python 3.7 + And it works.

Python modules not working in IDLE

Working on Automate The Boring Stuff project and having trouble with pyperclip and IDLE. pyperclip is successfully downloaded and works fine in Terminal but when I import pyperclip in IDLE, I get the below error.
UPDATE - This is happening with other modules - anything I've installed in the terminal aren't importing into IDLE.
import pyperclip
Traceback (most recent call last):
File "", line 1, in
import pyperclip
ModuleNotFoundError: No module named 'pyperclip'
I figure I have the module saved in the wrong folder somehow. Below are the sys.path outputs from my Terminal and IDLE.
In terminal:
'/anaconda/bin',
'//anaconda/lib/python36.zip',
'//anaconda/lib/python3.6',
'//anaconda/lib/python3.6/lib-dynload',
'//anaconda/lib/python3.6/site-packages',
'//anaconda/lib/python3.6/site-packages/Sphinx-1.5.1-py3.6.egg',
'//anaconda/lib/python3.6/site-packages/aeosa',
'//anaconda/lib/python3.6/site-packages/IPython/extensions',
'/Users/andrewricardo/.ipython']
In IDLE:
sys.path
['', '/Users/andrewricardo/Documents', '/Library/Frameworks/Python.framework/Versions/3.6/lib/python36.zip', '/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6', '/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/lib-dynload', '/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages']
There are multiple paths here - how do I effectively move the pyperclip module to the correct place?
OR - Is there something else going on here?
Each python installation and uses its own .../lib/site-packages for 3rd party modules, and you have two. If you ran the non-anaconda python in the terminal, the same that is running IDLE, it would have the same problem. Indeed, that python is the source of the ImportErrors.
Option 1: Separately install all packages you want to use with the non-anaconda python (and IDLE) in its own site-package directory. In IDLE Shell, get the path to its executable
>>> import sys; sys.executable
Save are remember the resulting 'python-path'. Then in the terminal, run
python-path -m pip install package-name
for each package.
Option 2 (uses a little known feature of site-package directories): in
/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages
add a file name, for instance, anaconda.pth, containing one line.
//anaconda/lib/python3.6/site-packages
(I have no idea why the double / or if it is really needed; I just copied it from your question.) This makes the anaconda python site-packages an extension of the framework python site-packages. Since both are for 3.6, one copy should work for both.
Had this same issue and googled
'why is importing pyperclip in my python file giving an "modulenotfounderror"but working fine in the idle'
and this page came up. then i also checked this [installed Pyperclip, trouble importing to IDLE.
I am new to python, had the same issue using the same book after pip installing pyperclip here's what I did to solve this issue.
I copied the pyperclip-1.7.0-py3.7.egg-info and pyperclip folders from
C:\Users\USER\AppData\Local\Programs\Python\Python37\Lib\site-packages into the C:\Users\USER\Anaconda3\Lib\site-packages folders and C:\Users\USER\AppData\Local\Programs\Python\Python37 folders and it worked. Hope this helps. If it doesn't. Try this code in your text editor because that's what I did using Atom and how i was able to solve it.
import sys
print(sys.executable)
Then copy the pyperclip-1.7.0-py3.7.egg-info and pyperclip folders into the path that the above code gives you.

Error executing the result of cx_freeze using pycrypto

I am trying to freeze a Little python program using pycrypto library in Windows. Last version of everything including cx_freeze.
After running >python setup.py build apparently everything goes nice.
But running the exe file generated reports the following error : ImportError: cannot import name _AES
The error is reported by AES.py file which is part of pycrypto lybrary.
I have copied the pycrypto structure in the same directory where setup.py is and I played with the contents of setup.py making a lot of subtle changes but I always get the same error.
Does someone know what I am missing?

py2exe generator not working

I ran this setup.py file
from distutils.core import setup
import py2exe, sys, os
sys.argv.append('py2exe')
setup(
options = {'py2exe': {'bundles_files': 1}},
windows = [{'script': "Driverscript.py"}],
zipfile = None,
)
This creates the executable file and packages but it wont run every time i try to run it it says that it encountered an error and had to close every time. Is there something else i need to do first or something wrong with my setup.py file? all input is greatly appreciated thanks
What's the output of your error log? That could mean a lot of things. I'm assuming you're compiling a windowing application? Are you running this application on Windows? You might want to run the application from the command line and see if you get any errors.

making a python program executable

from distutils.core import setup
import py2exe, sys, os
sys.argv.append('py2exe')
setup(
options = {'py2exe': {'bundle_files': 1}},
windows = [{'script': "single.py"}],
zipfile = None,
)
in this setup file for py2exe where it says single.py is that where I place the name of my program?
I don't know your py2exe tool, but we usually use this way to convert py to exe:
Download and install Standard Python Software:
http://www.python.org/download/
Download PyInstaller via link below:
http://pyinstaller.python-hosting.com/
Unpack the archive, that you have downloaded!
In this examople, the directory of the unpacked files:
In the <UNPACKED_FILES_DIR> directory, run Configure.py.
It must be run before trying to build anything.
Create a spec file for your project:
python Makespec.py -F -p <PYTHON_LIB_PATH> <PYTHON_SCRIPT>
-F: Produce a single file deployment.
-p <PYTHON_LIB_PATH>: Set base path for import (like using PYTHONPATH).
( e.g.: C:\Program Files\Python24\Lib\ )
<PYTHON_SCRIPT>: Path to python script.
6 Build your project!
python Build.py <SPECFILE>
<SPECFILE>: Path to the specfile, that have been created in step 4!
The full path to <SPECFILE>:
<UNPACKED_FILES_DIR>/<PYTHON_SCRIPT>/<PYTHON_SCRIPT>.spec
The binary file will be placed in the directory of <SPECFILE>.
If you can restrict your code, then Shed Skin, PyPy, or Cython make true, fast executables.
Py2exe, PyInstaller, or bbfreeze can package Python up to 2.7 into single executables.
Cx_Freeze packages Python up to 3.x into an executable plus many other files.
Yes. Are you making a windowing application or a console application? See the example setup.py files that came with py2exe.

Resources