I'm using Python x64 with everything installed, but I'm getting an unresolved import on FigureCanvasWxAgg. I can get up to matplotlib.backends.backend_wxagg but there's no FigureCanvasWxAgg to import from there.
I've also tried
from matplotlib.backends.backend_wxagg import * but it doesn't work either.
EDIT: Problem solved. I took a peek at my backend_wxagg.py file and found it to be completely different than the one listed here. So I copied that from version 0.99.1.1 into my 1.0.1 file. (I should probably just uninstall 1.0.1 matplotlib and use the older version.) Anyway, it got the examples working, so I'm happy.
What OS are you on, and how did you install matplotlib?
Your solution is quite likely to break things... You need to build and install the wx backend as you normally would. I'm not sure about the wx backend, but several of the other backends are C extensions, not just a simple python file.
The wx backend isn't built by default, so it's usually included as a separate package. (e.g. python-matplotlib-wx in the case of Suse) You'll need to install the wx backend through your package manager, as you normally would.
If you're on an OS without a package manager (e.g. windows, osx), the installer may or may not have the wx backend built depending on who built it and how it was configured. I know absolutely nothing about non-linux or BSD oses, so you're on your own there. Try looking wherever you downloaded your matplotlib binary from and see if they have a separate installer for the wx backend.
If you're building from source, you need to enable the wx backend and rebuild. To do this, edit the site.cfg file in your build directory. You may need to rename the default one (site.cfg.default, or something along those lines) to site.cfg, if you don't alread have a site.cfg file in your build directory.
Hope that helps!
Related
I think I've found a bug in matplotlib. I'm using anaconda as a package manager, but had to download matplotlib from github in order to edit it.
How do I import my modified version of matplotlib in order to test it? I tried using
import /absolute/path/to/modified/matplotlib
, but that didn't work. Ideally I would like to create a conda environment that uses the modified matplotlib instead of the original, so I can easily switch between the two.
How do you test and run a modified version of an open source library, without messing up your original version of the package? Is there a way to import a library from an absolute path?
Try this
import sys
sys.path.append('/absolute/path/to/modified/matplotlib')
import matplotlib # modified
Another option not mentioned, if you just put the matplotlib module (copy or move) in the directory of your project, python will check there first, find the version you put there, and look no further. This is exactly the reason why you shouldn't name your files, for example, math.py.
You can install a local version by telling anaconda to install the tar-ball of the package directly, i.e.
conda install package-version-py27.tar.bz2
You might also be able to use the --use-local argument.
See: https://github.com/conda/conda/issues/5266, https://github.com/conda/conda/issues/1884
i am trying to use PyMouse plugin on windows 8.1 .
i used this code to import library :
from pymouse.windows import PyMouse
but this error shows :
from win32api import GetSystemMetrics
ImportError: No module named
'win32api'
where is the problem? i am not sure that i install the library fine ! can you show how to install it on windows ?
The win32api module is part of PyWin32, so you need to install that.
Meanwhile, you should be installing things with pip whenever possible. Some packages aren't pip-installable, or have incorrect requirements specs, but most packages, if you try to pip install them, will either automatically fetch their dependencies or complain that they're missing.
Also it looks like PyMouse's documentation is wrong, because it claims to only require ctypes (which comes with Python 2.6+), not PyWin32, on Windows. You may want to file a documentation bug with them.
However, it looks like the PyMouse you were using was abandoned at version 0.4 about 6 years ago. It was then picked up by someone else, but, as the README says, it was later merged into PyUserInput. So, you probably want to use that instead.
Note that PyUserInput correctly mentions the other dependencies in its README. It also checks them in its setup.py file. So hopefully, all you have to do is:
pip install PyUserInput
… and it will either pull in PyWin32 and pyHook, or complain that you have to go get them manually.
I'm trying to use the lockfile module from PyPI. I do my development within Spyder. After installing the module from PyPI, I can't import it by doing import lockfile. I end up importing anaconda/lib/python2.7/site-packages/spyderlib/utils/external/lockfile.py instead. Spyder seems to want to have the spyderlib/utils/external directory at the beginning of sys.path, or at least none of the polite ways I can find to add my other paths get me in front of spyderlib/utils/external.
I'm using python2.7 but with from __future__ import absolute_import.
Here's what I've already tried:
Writing code that modifies sys.path before running import lockfile. This works, but it can't be the correct way of doing things.
Circumventing the normal mechanics of importing in Python using the imp module (I haven't gotten this to work yet, but I'm guessing it could be made to work)
Installing the package with something like pip install --install-option="--prefix=modules_with_name_collisions" package_name. I haven't gotten this to work yet either, but I'm guess it could be made to work. It looks like this option is intended to create an entirely separate lib tree, which is more than I need. Source
Using pip install --target=lockfile_from_pip. The files show up in the directory where I tell them to go, but import doesn't find them. And in fact pip uninstall can't find them either. I get Cannot uninstall requirement lockfile-from-pip, not installed and I guess I will just delete the directories and hope that's clean. Source
So what's the preferred way for me to get access to the PyPI lockfile module?
I want to import the paramiko module located in /usr/local/lib/python2.7/dist-packages. So, I imported it this way:
from usr.local.lib.python2.7.dist-packages import paramiko
I have an error syntax related to python2.7 (It considers 7 as a package located in python2 package)
I have both Python3.1.3 and Python2.7 installed. I program with Python3.1.3 only, however.
How can I resolve this problem ?
How about ?
import sys
sys.path.append('/usr/local/lib/python2.7/dist-packages')
import paramiko
UPDATED
The best solution is installing paramiko on Python3 env. Take a look at #DanielRoseman's answer. Or virtualenv is worth consideration. Here is a good tutorial. http://simononsoftware.com/virtualenv-tutorial/
I don't know why you think you need to include the full path. That directory will already be included in the Python path. You just need to do import paramiko.
Edit after comment Well you can't randomly import things that are installed for a different version. There are several backwards incompatibilities, and anything that has any compiled extensions will just not work at all.
You need to download and install paramiko for your 3.1 installation, rather than trying to use the 2.7 version. python3 pip install paramiko, as an example.
(Also, you shouldn't really be using 3.1. If you're using the Python 3 series you should upgrade to 3.4.)
I am trying to install Basemap, and beforehand I already have the prerequisite versions of Matplotlib, Python and Numpy working on my Mac. To install Basemap I am following the instructions in this website http://matplotlib.org/basemap/users/installing.html
I seemed to progress quite well with the steps, until the very end which is "Check your installation by running from mpl_toolkits.basemap import Basemap at the python prompt." I got "ImportError: cannot import name pyproj" from a line that reads "---> 30 from mpl_toolkits.basemap import pyproj".
Does anyone have any idea? Many thanks!
The compiled module could be accessible by python. To achieve that you should put the module into python path or you need to add the location of the module to PYTHONPATH environment variable.
To see the python installations paths you can write these lines to python shell:
import sys
for path in sys.path:
print(path)
The code will show the paths python is looking for modules.
After you compile the c library, you need to go to upper folder and run python setup.py install as it's said in the installation page. This will put python modules into one of your python paths.
I had the same problem installing basemap-1.0.7.
I found that the file
/usr/lib64/python2.6/site-packages/mpl_toolkits/basemap/init.py
had a reference to axes-grid1, but python lists only module axes_grid.
So I changed grid1 to grid and now basemap imports without error.
Had the same issue on OSX, found after much faffing that Basemap worked fine with a non-native version of python (for me 2.7.12 with everything under /opt/local/Library/Frameworks...) but not with the native version (for me 2.7.10 with most stuff under /System/Library/Frameworks... and Basemap under /Library/...). I did note also that under the native version there was already some mpl_tooklit content and without the permission to add Basemap there you end up with mpl_toolkit contents in multiple places. I wasn't sure if this was the problem specifically but as I said having it all under opt using non-native python was what solved this for me.