If I include numpy in my script the bundle application does not even open. However, if I run the application from the console everything is fine. So:
pyinstaller -w myScript.spec
with import numpy as np in one of the modules does not create a proper executable. However:
python3.7 myScript.py
runs without problems. Even more, if I comment the import numpy as np line the executable is created without problem. I have also used numpy in another console-only script without problems.
So, how can I make PyInstaller include numpy in the bundle app?
I checked the warn-myScript.txt file from PyInstaller and there are lots of modules from numpy.core that are not found, for example: numpy.core.sqrt.
But I have no idea where to find these modules.
I tried doing what j4n7 suggested here, but it did not work.
I am using Python3.7, numpy 1.15.4 and PyInstaller 3.4
I installed Python from the Python web page and numpy and Pyinstaller using pip.
In a different computer I installed Python3.7 from homebrew and I have the same problem
I installed miniconda and then created an environment with numpy 1.15.4, Pyinstaller 3.4 and python3.7.1. Within the environment, I can create the bundle app with no problem.
However, the bundle app goes to 600MB. I will start a new question regarding how to reduce the size of the bundle app.
Related
I'm trying to install python application on Windows with pyinstaller where I'm using tkcalendar. Application is working but the tkcalendar.Calendar isn't.
When I'm running application without installation everything works but if I do this, Calendar widget does not appear.
I think that pyinstaller sees this module but he has problems with modules that tkcalendar is using.
I tried to run pyinstaller with --path=/.../python/Lib/site-packages but this didnt worked. Also copying module files to application directory didn't help.
The issue does not come from tkcalendar but from the fact that PyInstaller does not detect second level imports. A way to solve this issue is explained in tkcalendar's documentation in the HowTos section:
When bundling an application with PyInstaller, there is an
issue with the
detection of the babel dependency of tkcalendar. This can be fixed by
using the --hidden-import option:
$ pyinstaller --hidden-import babel.numbers myscript.py
or by editing the .spec file:
hiddenimports=["babel.numbers"]
Add following code to your python script, while bundling with pyinstaller
import babel.numbers
If anyone found the same problem.
In tkcalendar 1.5.0 there is problem with import in calendar.py.
Locate the tkcalendar folder (probably /.../python/Lib/site-packages/tkcalendar) and under calendar.py add an additional import for the missing module:
import calendar
from babel.dates import format_date, parse_date, get_day_names, get_month_names
from babel.numbers import * # Additional Import```
I have the following problem with fbs and Python: I tried to compile Python code and wanted to create an executable .exe file in windows. The command fbs run works fine, but fbs freeze fails.
Package versions:
Python 3.6.4
PyInstaller: 3.4
PyQt5: 5.9.2
Packages that I import:
import re
from itertools import chain
import os
import pandas
from PyQt5.QtWidgets import *
from fbs_runtime.application_context.PyQt5 import ApplicationContext
The output of fbs freeze --debug you see in the attached image:
I used the pyinstaller command to create the exe. This was possible without fbs. Just pyinstaller with the standard comments pyinstaller "...." --onefile --noconsole.
It worked with Python 3.6.4 and pyinstaller 3.4. Perhaps 3.5 would also work. But I know at least that Python 3.8.0 with the newest pyinstaller (even development version from git) doesn't work. I used PyQt5, but some older version 5.12....
It's a bit intransparent...
Best regards,
Markus
fbs runs perfectly fine with python 3.6.x (I am using 3.6.8, PyQt 5.9.2, PyInstaller 3.4).
The python compiler can sometimes get confused if another error happens earlier in the stack. Generally if fbs freeze errors when fbs run works, that points to a library-include error.
See my answer here to include necessary python library resources in your ./src/freeze/windows/ directory and try freezing again: The 'google-api-python-client' distribution was not found and is required by the application with pyinstaller
I'm working on my first gui exe. I'm using the anaconda packages with spyder and the code works fine there. Math, pyplot, numpy, tkinter, and PIL are imported, and the app is fully functional with the exception of pyplot which will not show up when activated from a button widget.
If instead I create a simple exe with the code:
import numpy
import matplotlib.pyplot as plt
x=numpy.linspace(1,100)
fig,ax=plt.subplots()
lineData,=ax.plot(x,3*x)
I get one error during the initial build:
ModuleNotFoundError: No module named 'Crypto.Math'
and many warnings, but note that the analysis warning file contains no errors either.
Running the created exe, I get failure and cmd exits. Running from cmd initially instead and turning on debug and verbose imports yields tons of warnings, but no errors.
I've tried including hidden imports like 'matplotlib.pyplot','matplotlib','Crypto', and importing Crypto, to no avail. Crypto is not being called anywhere and the reference plot in the build folder says only pyinstaller imports it. I'm at a loss here for what the problem could be.
Packages in anaconda folder
Ok, so it turned out to be a simple fix. lineData,=ax.plot(x,3*x) will plot/show the figure in spyder/Ipython, but not when called in the exe or python standalone, so I had to add plt.show().
From there I made a virtual environment with the latest packages and needed to
downgrade numpy to 1.16.2 per this thread, and now everything works.
Happy October everyone,
I've successfully downloaded modules before using either the pycharm installer or pip through the command screen, but for some reason when installing matplotlib pycharm cannot recognize it. I've uninstalled and reinstalled, I've installed through both methods, I've followed past similar questions asked on this site which make sure that you have the same interpreter and that it was installed in the right folder (pycharm error while importing, even though it works in the terminal).
So, here's the whole problem. Here's is the simple code, submitted into both pycharm and IDLE:
import matplotlib.pyplot as plt
plt.plot([1,2,3],[2,1,3])
plt.show()
When submitted into IDLE, my plot appears. When submitted into pycharm, the following error appears:
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:/PythonProject/matplotlib.py", line 1, in <module>
import matplotlib.pyplot as plt
File "C:\PythonProject\matplotlib.py", line 1, in <module>
import matplotlib.pyplot as plt
ImportError: No module named 'matplotlib.pyplot'; 'matplotlib' is not a package
I am currently running Python 3.4, PyCharm 2016.2.3, and my matplotlib folders are indeed in my site-packages folder inside my Python34 folder. Also for further verification:
PyCharm installation
Please help I've become frustrated since this is the only module I've run into trouble with. I've scoured StackOverflow and related websites to help, I've made sure I have all the requirements, etc.
I guess if you named your current writing python module as matplotlib.py.That cause the python load your current writing module instead of the actual matplotlib.py, which triggers an error.
I recommend you to use virtualenv. Is not strictly necessary but is good for dividing your project environments.
This is how I tested matplotlib on my Windows 10 installation, hope it helps.
Be sure that you have the python 3 installation folder listed in your Windows PATH environment variable, should be already listed if you checked "Add Python 3.5 to PATH":
You need also to set the Scripts folder in your PATH environment variable usually should be this path:
C:\Users\<your username>\AppData\Local\Programs\Python\Python35\Scripts
If you don't do that you have to prepend python -m to every command below like this: python -m <command>, so the command below would be python -m pip install virtualenv. I prefer the first solution.
To test matplotlib on Pycharm I've used virtualenv, here is how; first install virtualenv:
pip install virtualenv
Then you create your virtual environment in a folder of your choice, in my case I used python_3_env_00:
virtualenv python_3_env_00
After that you can activate you python 3 virtual environment:
python_3_env_00/Scripts/activate.bat
Now you should see in your command line the active virtual environment (python_3_venv_00), like this:
Now you can install matplotlib:
pip install matplotlib
Fire up PyCharm and add your virtual environment as you project interpreter, go to File->Settings search for Project Interpreter click on the gear icon and Add Local and set the path of your virtual environment, should look like something like this:
Test it:
import sys
print(sys.path)
run this code in where the import worked, and run it in the Pycharm project. Compare the lists. Find out which path that is not present in Pycharm sys.path.
Before importing pyplot, append the missing path to sys.path.
import sys
sys.path.append("the path")
import matplotlib.pyplot as plt
Does this work?
Please follow below steps if you are still getting an error:
If you are using PyCharm, it automatically create virtualenv.
Ensure Scripts path is set into PATH
C:\Users\<Username>\AppData\Local\Programs\Python\Python37-32
Then open PyCharm and go to File-> settings. Search for Project Interpreter. You will see window like this
sample image
Click on setting icon -> Existing Environment -> click on ... give below path
C:\Users\Krunal\AppData\Local\Programs\Python\Python37-32\python.exe
Click on Apply -> ok and you are good to go.
After installing matplotlib When I was trying to use matplotlib.pyplot it was giving error module not found.
I browsed some white papers and found out that we also need to install scipy library to use the matplotlib so I used the below in my command prompt
python -mpip install scipy
Restarted my kernel session.
It worked!!!
I was also facing issue while importing matplotlib but it got resolved and now I am able to use it from pycharm as well.
Please make sure you should have visual c++ 14 installed in your system.
2.If you have more than two python version installed on your system then please install matplotlib from both the version.
Eg. pip install matplotlib
pip3 install matplotlib
If matplotlib is working from python idle then please check whether you are using correct interpreter in pycharm or not and try to choose pythonw.exe path from your installed location.
Hope this will help, Please do let me know if you are still facing issue.
I had similar issue but I solved it very easily on pycharm 2019.3.2. In case anyone looking for an easier solution:
I just opened the terminal window on pycharm and typed pip install matplotlib and it was all good to go. Every project has its own virtual environment. Opening terminal window of IDE cds to project directory by default. So the installing command was enough.
I'm trying to use cx_Freeze to generate a .app from a python project. Generally I have it working, but some of my modules which depend on scipy have an import error when executed:
No module named '_csr'
under the build folder I see a file:
scipy.sparse.sparsetools._csr.so
and watching the output of the build command seems to suggest that it's copying csr:
$ python3 setup.py bdist_mac | grep csr
m scipy.sparse.csr /usr/local/lib/python3.3/site-packages/scipy/sparse/csr.py
m scipy.sparse.sparsetools._csr /usr/local/lib/python3.3/site-packages/scipy/sparse/sparsetools/_csr.so
m scipy.sparse.sparsetools.csr /usr/local/lib/python3.3/site-packages/scipy/sparse/sparsetools/csr.py
? _csr imported from scipy.sparse.sparsetools.csr
? os.path imported from NIF_WRF.util.StopPow, distutils.file_util, matplotlib.backends.backend_tkagg, matplotlib.cbook, numpy.core.memmap, numpy.distutils.command.scons, os, pkg_resources, pkgutil, scipy.lib.blas.scons_support, scipy.lib.blas.setup, scipy.lib.lapack.scons_support, scipy.linalg.setup, scipy.sparse.csgraph.setup, scipy.sparse.linalg.dsolve.setup, scipy.sparse.linalg.eigen.arpack.setup, scipy.sparse.linalg.isolve.setup, scipy.sparse.sparsetools.bsr, scipy.sparse.sparsetools.coo, scipy.sparse.sparsetools.csc, scipy.sparse.sparsetools.csgraph, scipy.sparse.sparsetools.csr, scipy.sparse.sparsetools.dia, scipy.special.setup, shutil, sysconfig
? scipy.lib.six.moves imported from scipy.integrate.quadrature, scipy.interpolate.interpolate, scipy.interpolate.polyint, scipy.linalg.special_matrices, scipy.misc.common, scipy.optimize.anneal, scipy.optimize.linesearch, scipy.optimize.nonlin, scipy.sparse.base, scipy.sparse.compressed, scipy.sparse.coo, scipy.sparse.csc, scipy.sparse.csr, scipy.sparse.dok, scipy.sparse.lil, scipy.sparse.linalg.eigen.lobpcg.lobpcg, scipy.sparse.linalg.isolve.lgmres, scipy.spatial.distance, scipy.special.basic, scipy.stats.stats
copying /usr/local/lib/python3.3/site-packages/scipy/sparse/sparsetools/_csr.so -> build/exe.macosx-10.8-x86_64-3.3/scipy.sparse.sparsetools._csr.so
The problem seems to be related to this other question but that user seemed to solve it by building again, which hasn't helped here. Any ideas?
UPDATE
I mucked around in the .app package contents and found that renaming scipy.sparse.sparsetools._csr.so to _csr.so solves that error (though generates another similar one for another scipy component). It seems like the cx_Freeze script is not properly naming scipy inputs.
Also, here are the versions I'm using:
cx_Freeze: 4.3.2
scipy: 0.13.0
python: 3.3.2