cx_Freeze error: ModuleNotFoundError: No module named 'pydicom' - python

Problem: I get the error "ModuleNotFoundError: No module named 'pydicom'" when trying to run an executable created from a python program using cx_Freeze.
Background: I am using Python 3.8 with Anaconda 2020.02 on Windows 10 with PyCharm 2019.3.3 Community Edition as an editor, cx_Freeeze version 6.2, pydicom version 2.00. I am new to Python programming.
I had some initial trouble installing pydicom (pydicom-2.0.0-pyh9f0ad1d_0) and needed to go through the Anaconda Navigator to get it installed properly. Pydicom is not included with the standard package apparently.
Attempted: There are a lot of posts describing similar problems. I tried the following code for my setup.py but still no luck
from cx_Freeze import setup, Executable
packages = ['pydicom']
include_files = ["C:/<me>/.conda/pkgs/pydicom-2.0.0-pyh9f0ad1d_0/site-packages/pydicom"]
setup(name="MyProgram",
options={"build.exe": {'packages':packages, 'include_files':include_files}},
executables = [Executable("MyProgram.py")])
I fooled around with the include_files variable (e.g., ""C://.conda/pkgs/pydicom-2.0.0-pyh9f0ad1d_0/site-packages") with no luck.
I also use pandas in this code but there are no complaints when running (maybe it failed before executing any pandas code?)
Any suggestions welcome!
Thanks,
Tom

Related

how to build .exe for python 3.5+, 3.6 if possible?

Is there now an easy protocol to build a .exe from python 3.5+, using modules pyqtgraph, qt5, theano, pymc3, numpy, scipy, os and sys, and opening a simple GUI stored in a '.ui' file ? I lost hours and eventually failed to make one (for w7-64 bits). Help !
preliminary failure with py2exe: I first install py2exe for python 3 but it turns out this is not compatible with my python 3.6 yet, so I downgraded to python 3.5… to get a bunch of errors. Then I went to forums and tried the proposed cures but failed (I’m uneasy with windows), the alternative being to downgrade to python 3.4… So I downgraded to python 3.4 to get an error concerning a missing ‘msvcr100.dll’ that I tried to install following instructions on forums but by default I don’t have the permission to modify system directories… When I eventually had this permission it turns out the ‘regsvr32’ command fails (isn’t this for 32 bits ? but there is no ‘regsvr64’…). Following episodes are described below.
update august 23, 2017, 1pm:
I also tried pyinstaller as advised but it failed (see my related question build a .exe for Windows from a python 3 script importing theano with pyinstaller)
I also tried cx_freeze but it failed (see my related question build a .exe for Windows from a python 3 script)
I also tried pynsist but it fails (same link than above)
what's next ?
update september, 2, 2pm:
I eventually managed to build a .exe with pyinstaller after many episodes.
Unfortunately I failed to deal with the ‘theano’ module (that is required in my case by the ‘pymc3’ module) and I had to modify the .py files and give up part of the application. Could anyone help me building a .exe for windows 7+, with the ‘theano’ module ?
see build a .exe for Windows from a python 3 script importing theano with pyinstaller
Pyinstaller Works with Python 3.5 and it is working even for packages like tensor-flow, scipy , etc (The packages I worked with)
py -3.5 pip install pyinstaller
then go the C:\Users\user\AppData\Local\Programs\Python\Python35\Scripts
and run the command
pyinstaller <code .py file along with directory> --onefile
--onefile : is for compressing the build and get a single file as output
I would suggest pyinstaller see http://www.pyinstaller.org/
The pyinstaller already supports 3.5
The development version supports 3.6
It is better to use spec file to import other hidden libraries. I listed all Sklearn libraries and add them to spec file as a hiddenimports, you can add libraries you used in your project.

ImportError: No module named 'matplotlib'

Brand new to Python (typically program in MSDN C#) and I'm trying to make use of the matplotlib to generate some graphics from .csv files
I've downloaded & installed Python as well as Anaconda onto my Windows 10 machine, the versions are Python 3.5.2 and Anaconda 4.1.1
I open up the Python "notepad" interface and do
import matplotlib.pyplot as plt
plt.plot([1,2,3],[3,2,1])
plt.show()
but when I run the code I get the error:
ImportError: No module named 'matplotlib'
I've looked at some other posts for this but they all seem to be in regard to Mac OSX or Linux. Some have pointed to multiple installs of matplotlib, but I haven't turned up such a situation so far. What might be causing this, or how can I troubleshoot it?
**Edit:
The path returned to me from the import sys recommended in the comments gave me this response
['C:\Users\a.watts.ISAM-NA\Desktop',
'C:\Users\a.watts.ISAM-NA\AppData\Local\Programs\Python\Python35-32\python35.zip',
'C:\Users\a.watts.ISAM-NA\AppData\Local\Programs\Python\Python35-32\DLLs',
'C:\Users\a.watts.ISAM-NA\AppData\Local\Programs\Python\Python35-32\lib',
'C:\Users\a.watts.ISAM-NA\AppData\Local\Programs\Python\Python35-32',
'C:\Users\a.watts.ISAM-NA\AppData\Local\Programs\Python\Python35-32\lib\site-packages',
'C:\Users\a.watts.ISAM-NA\AppData\Local\Programs\Python\Python35-32\lib\site-packages\setuptools-26.1.1-py3.5.egg']
You essentially have 2 versions of python on your system - the standard one you downloaded and the one that ships with Anaconda. When you are running code in the IDLE you are using the standard version (in C:\Users\a.watts.ISAM-NA\AppData\Local\Programs\Python\Python35-32\python.exe) where matplotlib isn't installed which is why you are getting the error.
You need to use the Anaconda version (C:\Users\a.watts.ISAM-NA\AppData\Local\continuum\anaconda3\python.exe) that comes with the scientific stuff already setup. It looks like your system is using this one from the cmd so if you run scripts from there it should use the Anaconda version. If you want to use something more interactive you can also use spyder - the Anaconda version of the IDLE - or run jupyter notebook from cmd to get a browser based platform for interactive development

cx_Freeze giving error when using fuzzywuzzy

I have built a tkinter GUI for survey entry in python3.4 that uses a number of packages. I then need to compile it to an executable so that I can put it on a coworkers machine (we both are on windows7 platform) I've structured my setup.py to look like:
from cx_Freeze import setup, Executable
import sys
base = None
if sys.platform == "win32":
base = "Win32GUI"
setup(
name='Survey Entry',
version='3.5',
license='MIT',
description='GUI For entering survey data',
executables= [Executable("Survey Entry.py", base=base)],
options={"build_exe":{"packages":['tkinter','cx_Oracle','datetime','time','enter_survey','lookup',
'queryfuncs','login','gui', 'datetime', 'add_respondent', 'possible_matches']}}
)
This worked absolutely fine for tons of versions. But then I added a functionality that uses fuzzywuzzy to compare strings. When I include that and add fuzzywuzzy to the packages list in the options dictionary and compile it, I get a big error when I try to run the exe that ends with ImportError: No module named 'Levenshtein'
I don't understand because in my development the module works fine. I've tried to include Levenshtein in the setup but it doesn't exist as a module. I don't have python-Levenshtein installed though because I can't get the .whl to install on my windows machine.
Has anyone ran into this? Why would fuzzywuzzy cause this error when it runs fine through python? Is there something I'm missing?
The complete error can be seen here: http://imgur.com/a/rSKsS
EDIT: I was able to figure it out - I need the python-Levenshtein module installed, had to keep working at it to get the .whl to install (apparently I'm not as proficient with the command prompt as I wanted to believe). After that I included Levenshtein and fuzzywuzzy in the packages list and it compiled without error.
I'm going to leave this up because I couldn't find this on a google search so hopefully no one else falls victim!
Found the solution - python-Levenshtein needs to be installed. Got mine from gohlke's repository: http://www.lfd.uci.edu/~gohlke/pythonlibs/#python-levenshtein - make sure you have the platform that matches your python installation! I run a x64 windows but I use x32 python for compatibility with my Oracle driver - so I needed to install the 32-bit module.

cx_freeze compiled python - importError

I am trying to run compiled Python executable (python 3.5 win-64) with cx_freeze from different computers and I have faced such problem
ImportError: Missing required dependencies ['numpy']
The problem is that it works on my computer where I created the script, but on others it refers to my computer as a library path.
But why? I thought that compiled python script contains all libs inside itself.
I tried to include numpy into packages list within setup.py
packages = ['scipy', 'pandas', 'sklearn', 'dill', 'getpass', 'numpy']
But the error is still there.

Import Module error when using cx_Freeze (PYTHON)

I have spent the last 2 hours searching the web to find very little and nothing that helps.
Hoping someone here will be able to help me.
When using cx_Freeze to convert my .py file to a .exe files, I get an error stating no module named xlsxwriter can be found.
When this module is removed from the packages list the program compiles with no problem.
My code:
import cx_Freeze
Executables = [cx_Freeze.Executable("test.py")]
cx_Freeze.setup(
name="Sort PLL Bale Lists",
options={"build_exe": {"packages":['xlrd','xlsxwriter']}},
executables = Executables
)
Try adding includes list to your code eg: includes = [xlrd,xlsxwriter]. Refer to this SO post for help. If the error persists try installing xlrdwriter with pip install xlsxwriter.
There is a chance that you have xlrd already installed and you have not installed xlsxwriter. This can be verified with pip freeze. pip freeze will provide a list of installed packages.

Categories