I'm having trouble figuring out an error message in Python.
yesterday, I've installed python using the latest EPD package, and wxPython2.9 using the wxPython2.9-osx-cocoa-py2.7 package for Mac OS.
I then added wx to my PYTHONPATH.
export WXDIR=/usr/local/lib/wxPython-2.9.1.1/lib/python2.7/site-packages/wx-2.9.1-osx_cocoa
export PYTHONPATH=$WXDIR
export PYTHONPATH=$PYTHONPATH:$WXDIR/tools
but when I try to run stuff I get this error:
In [14]: import matplotlib.pyplot
---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
/Users/imrisofer/Documents/third/hddm-read-only/hddm/<ipython console> in <module>()
/Library/Frameworks/EPD64.framework/Versions/7.0/lib/python2.7/site-packages/matplotlib/pyplot.py in <module>()
93
94 from matplotlib.backends import pylab_setup
---> 95 new_figure_manager, draw_if_interactive, show = pylab_setup()
96
97 #docstring.copy_dedent(Artist.findobj)
/Library/Frameworks/EPD64.framework/Versions/7.0/lib/python2.7/site-packages/matplotlib/backends/__init__.py in pylab_setup()
23 backend_name = 'matplotlib.backends.%s'%backend_name.lower()
24 backend_mod = __import__(backend_name,
---> 25 globals(),locals(),[backend_name])
26
27 # Things we pull in from all backends
/Library/Frameworks/EPD64.framework/Versions/7.0/lib/python2.7/site-packages/matplotlib/backends/backend_wxagg.py in <module>()
21
22 from backend_agg import FigureCanvasAgg
---> 23 import backend_wx # already uses wxversion.ensureMinimal('2.8')
24 from backend_wx import FigureManager, FigureManagerWx, FigureCanvasWx, \
25 FigureFrameWx, DEBUG_MSG, NavigationToolbar2Wx, error_msg_wx, \
/Library/Frameworks/EPD64.framework/Versions/7.0/lib/python2.7/site-packages/matplotlib/backends/backend_wx.py in <module>()
43 import wxversion
44 except ImportError:
---> 45 raise ImportError(missingwx)
46
47 # Some early versions of wxversion lack AlreadyImportedError.
ImportError: Matplotlib backend_wx and backend_wxagg require wxPython >=2.8
I can successfully import wx, so I don't no what's the problem.
Am I missing anything in the PYTHONPATH?
In Ubuntu 12.04, this problem can be solved by running the command
sudo apt-get install libjpeg62
I realize this may not be useful here, but I wanted to document it somewhere on teh interwebz so I can find it when I run into this problem again myself which will undoubtedly happen.
I'm using Ubuntu 13.10, Canopy 1.2, and PyCharm 3.0.2. When trying to use matlablib, it always complains "Matplotlib backend_wx and backend_wxagg require wxPython >=2.8".Pretty sure that I'm using wxPython 2.8. Then I tried all the methods described in this page, but neither of them works for me.
It turns out that it can be solved by modifying matplotlibrc file. There is a line:
backend : WXAgg
In fact we can change the backend to whatever we like, and I change it to TKAgg, which works just fine for me.
Select your wx version before importing any wx modules
import wxversion
wxversion.select('2.8')
The above code should come before import wx
This happened to me on a Windows x64 installation that did not install wxversion.py in the site-packages directory (c:\Python27\Lib\site-packages by default).
You can get a copy of wxversion.py from the WX svn repository:
http://svn.wxwidgets.org/viewvc/wx/wxPython/trunk/wxversion/wxversion.py?content-type=text%2Fplain&view=co
this link helped me
https://support.enthought.com/entries/22601196-wxPython-2-8-and-2-9
Here's how I fixed the problem, which I hope will be useful for others in future
In Terminal: gedit Enthought/Canopy_64bit/User/lib/python2.7/site-packages/matplotlib/mpl-data/matplotlibrc
Edit the line "backend : WXAgg" into "backend : QtAgg"
Save and exit
I just ran into this myself. One potential cause of this (quite unhelpful) error message is if you installed wx as a single-version installation (INSTALL_MULTIVERSION=0 when running setup.py). In this case, the module wxversion does not get built (or installed) and as such matplotlib incorrectly assumes that all of wx is missing.
This currently is the default setting in installations by the homebrew version of wxWidgets (wxmac) with the option --python.
In your case (albeit a year and a half late), you'd need to ensure that wxversion.py exists within /usr/local/lib/wxPython-2.9.1.1/lib/python2.7/site-packages/. If it doesn't, you'd need to recompile wx with the above flag set. Otherwise you just need to set your $PYTHONPATH such that it includes the base site-packages directory, too:
export WXDIR=/usr/local/lib/wxPython-2.9.1.1/lib/python2.7/site-packages
export PYTHONPATH=$WXDIR:$WXDIR/wx-2.9.1-osx_cocoa:$WXDIR/wx-2.9.1-osx_cocoa/tools
I've solved with this:
defaults write com.apple.versioner.python Prefer-32-Bit -bool yes
I solved this by setting the backend to MacOSX in ~/.matplotlib/matplotlibrc:
backend : MacOSX
I've solved this on Windows by looking in the site packages folder in the python library. In there, there should be another folder titled site-packages. In this subfolder, there is the wxversion library. If you copy this library into the Lib folder in python, this import error should be averted.
sudo apt-get install python-wxtools
Install it. Worked for me.
Related
I'm trying to import ocrmypdf on my company's client's Windows Server 2016 Build 14393 computer using Python 37-32. When I import the library, in a Jupyter Notebook, it is unable to locate leptonica by using ctypes.utility.find_library().
Ocrmypdf is a Linux-developed Python 3 package. Per the documentation (https://ocrmypdf.readthedocs.io/en/latest/introduction.html) it does not support Windows. The suggested workarounds are a docker container and Windows Subsystem for Linux.
I would rather not use a docker container as neither I nor my coworkers are very experienced with it. I am unable to use wsl as it is not available for my build of Windows Server 2016 (see the troubleshoot subsection: https://learn.microsoft.com/en-us/windows/wsl/install-on-server)
This discussion (find_library() in ctypes) states that you can point ctypes.utility.find_library to the needed library file by editing the environment Path variable to be a folder which includes it. Conveniently, Tesseract OCR's windows download includes liblept. Would editing the Path variable to point toward that folder be a dangerous thing to do?
Edit: I tried adding the path to Tesseract-OCR's folder on my laptop's environment Path and restarted Anaconda, etc. ocrmypdf still gave the same error.
A closer read of that discussion brought up the point that find_library operates differently on Windows. A read of the documentation (https://docs.python.org/2.5/lib/ctypes-finding-shared-libraries.html) states that "On Windows, find_library searches along the system search path, and returns the full pathname, but since there is no predefined naming scheme a call like find_library("c") will fail and return None." Does this mean I have to hardcode in a name to use in order to find the library?
This issue has been replicated, albeit on a different machine, here: https://github.com/jbarlow83/OCRmyPDF/issues/341. You can reproduce the issue by running the below code on a Windows machine.
!pip install ocrmypdf
import ocrmypdf
The expected result of the above code is that ocrmypdf is successfully imported in a usable form.
The result of the above code is:
OSError Traceback (most recent call last)
<ipython-input-2-a81f3474d7ad> in <module>
----> 1 import ocrmypdf
~\AppData\Local\Continuum\anaconda3\lib\site-packages\ocrmypdf\__init__.py in <module>
16 # along with OCRmyPDF. If not, see <http://www.gnu.org/licenses/>.
17
---> 18 from . import helpers, hocrtransform, leptonica, pdfa, pdfinfo
19 from ._version import PROGRAM_NAME, __version__
20 from .api import Verbosity, configure_logging, ocr
~\AppData\Local\Continuum\anaconda3\lib\site-packages\ocrmypdf\leptonica.py in <module>
40 logger = logging.getLogger(__name__)
41
---> 42 lept = ffi.dlopen(find_library('lept'))
43 lept.setMsgSeverity(lept.L_SEVERITY_WARNING)
44
OSError: cannot load library '<None>': error 0x57
I have been able to get this working Windows 10 by updating the path and it works fine. I used msys2 to install it, hence, the path name. Update to point where your liblept-5.dll is located.
if os.name == 'nt':
os.environ['PATH'] = os.environ.get("PATH", "") + ';C:\\msys64\\mingw64\\bin'
i try to train.py in object_detection in under git url
https://github.com/tensorflow/models/tree/master/research/object_detection
However, the following error occurs.
ModuleNotFoundError: No module named 'object_detection'
So I tried to solve the problem by writing the following code.
import sys
sys.path.append('/home/user/Documents/imgmlreport/inception/models/research/object_detection')
from object_detection.builders import dataset_builder
This problem has not been solved yet.
The directory structure is shown below.
~/object_detection/train.py
~/object_detection/builders/dataset_bulider.py
and here is full error massage
/home/user/anaconda3/lib/python3.6/site-packages/h5py/init.py:34: FutureWarning: Conversion of the second argument of issubdtype from float to np.floating is deprecated.
In future, it will be treated as np.float64 == np.dtype(float).type.
from ._conv import register_converters as _register_converters
Traceback (most recent call last):
File "train.py", line 52, in
import trainer
File"/home/user/Documents/imgmlreport/inception/models/research/object_detection/trainer.py", line 26, in
from object_detection.builders import optimizer_builder
ModuleNotFoundError: No module named 'object_detection'
how can i import modules?
Try install Tensorflow Object Detection Library Packaged
pip install tensorflow-object-detection-api
Cause of this error is installing object_detection library, So one of the solution which can work is running the below command inside models/research
sudo python setup.py install
If such solution does not work, please execute the below command one by one in the directory models/research
export PYTHONPATH=$PYTHONPATH:`pwd`:`pwd`/slim
sudo python setup.py install
I hope this will work. I also faced the same problem while creating model from export_inference_graph.py. It worked for me.
You need to export the environmental variables every time you open a new terminal in that environment.
Please note that there are are back quotes on each of the pwd in the command as this might not be showing in the command below. Back quote is the same as the tilde key without pressing the shift key (US keyboard).
From tensorflow/models/research/
export PYTHONPATH=$PYTHONPATH:`pwd`:`pwd`/slim
try this:
python setup.py build
python setup.py install
There are a number of modules in the object_detection folder, and I have created setup.py in the parent directory(research folder) to import all of them.
from setuptools import find_packages
from setuptools import setup
REQUIRED_PACKAGES = ['Pillow>=1.0', 'Matplotlib>=2.1', 'Cython>=0.28.1']
setup(
name='object_detection',
version='0.1',
install_requires=REQUIRED_PACKAGES,
include_package_data=True,
packages=[p for p in find_packages() if p.startswith('object_detection')],
description='Tensorflow Object Detection Library',
)
You did have "sys.path.append()" before you imported the object detection, so I am surprised that you are facing this error!
Please check that the path you have used in sys.path.append() is right.
Well, the only and obvious answer for the error is that the path of the module is not added properly.
Besides the various ways mentioned here, here is a way in which you can add the "object_detection" path permanently to the PYTHONPATH variable.
If you are using a Linux system, here is how you would go about it:
Go to the Home directory. Press Ctrl + H to show hidden files. You will see a file called ".bashrc". Open this file using a code editor (I used Visual Studio).
In the last line of .bashrc file, add the line:
export PYTHONPATH=/your/module/path:/your/other/module/path:your/someother/module/path
Then press "save" in the code editor. Since ".bashrc" is a "Read-only" file the editor will throw a pop-up saying the same. Also in the pop-up there will be an option that says: "Try with sudo". Hit this button and now you are good to go.
All your modules are now permanently added to the PYTHONPATH. This means that you need not run sys.path.append every time you open your terminal and start a session!
Below is the screenshot with no error when I followed the said steps:
Try this. I hope it helps.
And finally, If you've followed all the steps here and are at your wit's end...make sure the file that you're running (the one with your source code in it ya know), isn't named object_detection.py - that would preclude it being searched for as a module.
Certainly I've never done anything like this that led me to add an embarrassing answer on Stack Overflow...
I had to do:
sudo pip3 install -e . (ref)
sudo python3 setup.py install
System:
OS: Ubuntu 16.04, Anaconda (I guess this is why I need to use pip3 and python3 even I made virtual environment with Pyehon 3.8)
I am trying to use a ctypes-based wrapper for librsync on Linux which are installed in a non-standard path. However:
----> 1 import librsync
/home/ptest/lib/python2.7/site-packages/librsync/__init__.py in <module>()
11 path = ctypes.util.find_library('rsync')
12 if path is None:
---> 13 raise ImportError('Could not find librsync, make sure it is installed')
14 try:
15 _librsync = ctypes.cdll.LoadLibrary(path)
ImportError: Could not find librsync, make sure it is installed
LD_LIBRARY_PATH has been set prior, but ctypes doesn't seems to honor it. The search suggested many questions asked along this line, but I can't seem to find a solution. Any help?
Starting with Python 3.6, it does.
For earlier versions, #eryksun suggested this workaround:
os.environ['LIBRARY_PATH'] = os.environ['LD_LIBRARY_PATH']
do this before:
sudo apt-get install librsync-dev
I've been struggling to get pytables and the underlying HDF5 library working on python in OS X, so thought I'd give the Enthought distribution a go (which will also greatly simplify deployment across platforms later on).
I installed EPD 7.3 for 64-bit OS X (I'm running 10.8.2), but unfortunately no success, I get the following when trying to load the pytables...
In [4]: import tables
--------------------------------------------------------------------------- ImportError Traceback (most recent call last) /<ipython-input-4-389ecae14f10> in <module>()
----> 1 import tables
/Users/davidperry/Library/Python/2.7/lib/python/site-packages/tables/__init__.py in <module>()
57
58 # Necessary imports to get versions stored on the Pyrex extension
---> 59 from tables.utilsExtension import getPyTablesVersion, getHDF5Version
60
61 __version__ = getPyTablesVersion()
ImportError: dlopen(/Users/davidperry/Library/Python/2.7/lib/python/site-packages/tables/utilsExtension.so, 2): Symbol not found: _SZ_BufftoBuffCompress Referenced from: /Users/davidperry/Library/Python/2.7/lib/python/site-packages/tables/utilsExtension.so Expected in: flat namespace in /Users/davidperry/Library/Python/2.7/lib/python/site-packages/tables/utilsExtension.so
I presume this means that szip, a required library for HDF5, cannot be found? If it is actually missing from EPD (seems odd...), can I install it myself without building HDF5 from source? Or is is just in a strange place?
First, I apologize for the problems you are encountering.
It looks as if you are not loading pytables from EPD, but from a former installation. How does PYTHONPATH look like in your environment ?
Generally, EPD is installed somewhere in /Library/Frameworks/Python.framework/Versions/7.3. What does the following do ?
PYTHONPATH= /Library/Frameworks/Python.framework/Versions/7.3/bin/python -c "import tables; print tables.__version__"
or (64 bits version):
PYTHONPATH= /Library/Frameworks/EPD64.framework/Versions/7.3/bin/python -c "import tables; print tables.__version__"
It should return you something like "2.3.1" (the actual tables version available in EPD). If that indeed works, then do make EPD the default python in your environment, you will need to adapt the PATH/PYTHONPATH variables to make it available.
If that still does not work, then can you try the following (adapt for 32 bits):
PYTHONPATH= /Library/Frameworks/EPD64.framework/Versions/7.3/bin/python -c "import sys; print sys.path"
and paste the output ?
I recently installed the enthoughts distribution of python and started to go through the examples as outlined here
http://www.enthought.com/products/epdgetstart.php?platform=mac
i.e.
EPD comes with a number of examples to get you started. To run the scripts in the Examples subdirectories, simply launch IPython and type run .
I executed the following and received a run time error which I'm not sure how to interpret as I am a new to python and enoughts.
mycomputer:demo$ ipython
In [1]: run multiaxis_using_Plot.py
---------------------------------------------------------------------------
RuntimeError Traceback (most recent call last)
/Library/Frameworks/EPD64.framework/Versions/7.1/Examples/chaco-4.0.0/demo/multiaxis_using_Plot.py in <module>()
14 from scipy.special import jn
15
---> 16 from chaco.example_support import COLOR_PALETTE
17 # Enthought library imports
18 from enable.api import Component, ComponentEditor
/Library/Frameworks/EPD64.framework/Versions/7.1/lib/python2.7/site-packages/chaco/example_support.py in <module>()
47 pass
48 else:
---> 49 raise RuntimeError("Can't load wx or qt4 backend for Chaco.")
50
51
RuntimeError: Can't load wx or qt4 backend for Chaco.
In [2]:
In [2]: pwd
Out[2]: u'/Library/Frameworks/EPD64.framework/Versions/7.1/Examples/chaco-4.0.0/demo'
Any insights on what might be going on? I greatly appreciate it.
User 'minrk' answered this question:
As described on the 64bit EPD download page, several GUI toolkits (definitely Wx, and I think Pyglet as well) are not functional when run in 64bit mode on EPD on OS X. It is recommended that if you want to use the GUI tools on OSX, you use 32bit EPD. – minrk