I tried to use Basemap package to plot a map by PyCharm, but I got something wrong with
from mpl_toolkits.basemap import Basemap`
And the Traceback as followed:
Traceback (most recent call last):
File "/Users/yupeipei/anaconda3/lib/python3.6/site-packages/IPython/core/interactiveshell.py", line 2963, in run_code
exec(code_obj, self.user_global_ns, self.user_ns)
File "<ipython-input-4-0a24a3a77efd>", line 7, in <module>
from mpl_toolkits.basemap import Basemap
File "/Applications/PyCharm.app/Contents/helpers/pydev/_pydev_bundle/pydev_import_hook.py", line 20, in do_import
module = self._system_import(name, *args, **kwargs)
File "/Users/yupeipei/anaconda3/lib/python3.6/site-packages/mpl_toolkits/basemap/__init__.py", line 146, in <module>
pyproj_datadir = os.environ['PROJ_LIB']
File "/Users/yupeipei/anaconda3/lib/python3.6/os.py", line 669, in __ getitem__
raise KeyError(key) from None
KeyError: 'PROJ_LIB'
I'm confused with this error on PyCharm, because the same script is running correctly on Jupyter or Spyder! The environment in PyCharm is ../anaconda3/lib/python3.6 where is same from anaconda.
Has anyone met this error before?
Could anyone can help me to solve this error?
For Windows 10 with Anaconda + Python 3.71 (and I'm sure other Python 3 versions and Windows 7/8), you can tell Basemap where Proj4's "epsg" file is to succeed. I don't have an "environment" or whatever because it's too much work to figure out - so I didn't have an anaconda\share\proj area (as far as I could discern why I didn't have it).
But, what Basemap wants is the file "epsg", search the Anaconda directory for it with Windows Explorer. If it doesn't find it, install Proj4 by opening the "Anaconda Prompt" and typing in:
conda install -c conda-forge proj4
If it finds it, it should be in something like:
C:\Utilities\Python\Anaconda\Library\Share (it's where mine was, as well as \pkgs\ places where I guess it puts the package itself - and those can work too if need be, I used them at first, but the library one should work through updates better (maybe)).
Use the following code before importing Basemap and it'll work. Sets the environment variable PROJ_LIB to wherever epsg is and then Basemap can be happy.
import os
os.environ["PROJ_LIB"] = "C:\\Utilities\\Python\\Anaconda\\Library\\share"; #fixr
from mpl_toolkits.basemap import Basemap
As a nice bonus, to get hi-res data of Basemap, which Anaconda doesn't include in the Basemap install to start, type into "Anaconda Prompt":
conda install -c conda-forge basemap-data-hires
Following mewahl's comment I've added to my .bashrc (I use bash):
export PROJ_LIB=/path/to/your/instalation/of/anaconda/share/proj/
and now basemap (and others work).
You have to set the path of Proj lib as in newer version , this path has been replaced.
Write below two lines of code before importing matplot_toolkits
### For Window's Users
import os
os.environ['PROJ_LIB'] = r'C:\Users\XXXXX\Anaconda3\pkgs\proj4-5.2.0-
ha925a31_1\Library\share'
To find the path of Proj_lib , just search epsg and then copy this epsg file location and put in proj_lib .
Your Problem will be solved.
### For Linux's Users
import os
os.environ['PROJ_LIB'] = r'/home/XXXXXX/anaconda3/pkgs/proj4-5.2.0-
he6710b0_1/share/proj'
The answer is from Github and it worked for me.
import os
import conda
conda_file_dir = conda.__file__
conda_dir = conda_file_dir.split('lib')[0]
proj_lib = os.path.join(os.path.join(conda_dir, 'share'), 'proj')
os.environ["PROJ_LIB"] = proj_lib
from mpl_toolkits.basemap import Basemap
This worked for me:
import os
os.environ["PROJ_LIB"] = os.path.join(os.environ["CONDA_PREFIX"], "share", "proj")
This extends #Yusuf Baktir 's answer by omitting hard-coding the path to the epsg file. This way the code works on any machine that has conda installed (and activated of course).
This seems to be a common issue. There are several bug reports about it
basemap/issues/419,
https://github.com/matplotlib/basemap/issues/428
basemap/issues/428
I had run into this error myself, and for me the solution was to uninstall basemap 1.2, then install basemap 1.1 from an old wheel file I still had lying around and then install basemap 1.2 again. I honestly have no idea why that worked though.
Also from those issues above there are all kinds of other solutions that people have reported to work for them. Hopefully one of them fits here as well.
Proj4 easy solution to fix on pycharm is goto setting-> project interpreter -> + -> write proj4 in the search field and install.
I was not able to solve this problem but I was able to find an alternate, use CartoPy.
basemap is being maintained for python 2.7 users.
CartoPy is a better alternative
I faced same problem. I installed anaconda and install conda install -c anaconda basemap.
I used Anaconda built in IDE named "Spyder".
Spyder is better than pycharm. only problem with spyder is lack of intellisense.
I solved problem of Proj4 by setting path.
Other problem kernel restarting when loading of .json larger file dataset.
I use notepad++ and 010 editor to re-save file in small chunks and at last I merged all outputs.
Related
I'm trying to work with the openai gym module but I get this error:
>>> import atari_py
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Users\ssit5\AppData\Local\Programs\Python\Python38\lib\site-packages\atari_py\__init__.py", line 1, in <module>
from .ale_python_interface import *
File "C:\Users\ssit5\AppData\Local\Programs\Python\Python38\lib\site-packages\atari_py\ale_python_interface.py", line 17, in <module>
ale_lib = cdll.LoadLibrary(os.path.join(os.path.dirname(__file__),
File "C:\Users\ssit5\AppData\Local\Programs\Python\Python38\lib\ctypes\__init__.py", line 451, in LoadLibrary
return self._dlltype(name)
File "C:\Users\ssit5\AppData\Local\Programs\Python\Python38\lib\ctypes\__init__.py", line 373, in __init__
self._handle = _dlopen(self._name, mode)
FileNotFoundError: Could not find module 'C:\Users\ssit5\AppData\Local\Programs\Python\Python38\lib\site-packages\atari_py\ale_interface\ale_c.dll' (or one of its dependencies). Try using the full path with constructor syntax.
I don't have an ale_c.dll and tried finding solutions but nothing worked.
I followed the solution here https://github.com/openai/gym/issues/1726 but when trying to import atari_py it comes up with the same error. I don't see why the __init__ would search for something that didn't come with the module either. There were other StackOverflow questions that I looked at but they also yielded no results. The only solution I can think of is to get a copy of ale_c.dll but I don't know how I would get it.
I was facing the same error. Fortunately, I was able to find one workaround. Follow this steps and you should be good to go.
Download ale_c.dll from here.
Copy it in C:\Users\Deep Raval\AppData\Local\Programs\Python\Python38\Lib\site-packages\atari_py\ale_interface (Your path can be different).
Try to download arari-py package from conda
conda install -c conda-forge atari_py
this will fix your problem even if you are using Python > 3.7
For anybody else in the future, my problem was that I got the same error but I already had the ale_c.dll file in the right folder.
I followed a solution on this link --> https://github.com/openai/gym/issues/1726
I have tried to make it work with python 3.8 and 3.9 on Windows 10. Installing Python 3.7 and using it as the Python Interpreter on PyCharm resolved the issue. I have searched for the missing file while having 3.8 + version of Python and it did not exist at all. Atari-py is supported only for Python 3.7 (https://github.com/openai/atari-py) so having a higher version of that would not work. It is a bad idea to download files from unlicensed places so I advise you to install the supported version of Python (3.5, 3.6, and 3.7). Even though gym can work on 3.9 the atari version will not.
Just an update because gym 0.21.0 came out which supports ale-py and no longer uses atari-py (so any game marked v0 - v4 will no longer work if you use gym 0.21.0 and ale-py (which is supposed to come with gym). Make sure when you install your libraries that they are actually compatible.
Link to new version of gym https://brosa.ca/blog/ale-release-v0.7. When running v5 I do manage to render the game but I cannot find the other supported games. If you use gym 0.21.0 you will not need atari-py (atari_py).
From the example:
import gym
env = gym.make('ALE/Breakout-v5',
obs_type='rgb', # ram | rgb | grayscale
frameskip=5, # frame skip
mode=0, # game mode, see Machado et al. 2018
difficulty=0, # game difficulty, see Machado et al. 2018
repeat_action_probability=0.25, # Sticky action probability
full_action_space=True, # Use all actions
render_mode=None # None | human | rgb_array
)
it does actually run but the game is broken even in older versions of gym.
What I managed to get working after trying various python, gym and atari-py versions is:
I would suggest to the downloade the wheel file for you Windows and Python version from here: https://pypi.org/simple/atari-py/
and then execute pip install on this file like:
pip install atari_py-0.2.9-cp39-cp39-win_amd64.whl
This one helped for me (solution from github seems much much better, but it was not working for me - maybe because of venv? ) - for me it's a more safe solution than downloading a .dll from google drive.
This is a problem that you may face when using Windows.
Uninstall and reinstall atari using:
pip install -f https://github.com/Kojoley/atari-py/releases atari_py
I have ggplot successfully installed in my python 3.6.3 using the code below:
conda install -c conda-forge ggplot
But when I import it in my notebook using the code below, I get an error:
from ggplot import *
ImportError: cannot import name 'Timestamp'
I would appreciate any idea on how I can solve this problem.
I have encountered the same problem.
Please go to .../site-packages/ggplot/stats/smoothers.py and change
from pandas.lib import Timestamp
to
from pandas import Timestamp
and save.
#Liaoming999 is correct but adding more changes to resolve this problem:
Open file ../site-packages/ggplot/stats/smoothers.py
Change from pandas.lib import Timestamp to from pandas import Timestamp in line 4
Change pd.tslib.Timestamp to pd.Timestamp in line 14.
Save the file
Open file ../site-packages/ggplot/utils.py and goto line 81 and do the same as step 3. Thanks to #wmsmith for this tip.
p.s.: General advise is to use Anaconda or some Virtual env.
I encountered the same problem after upgrading to pandas 0.23 on a databricks server.
Had to come up with this command-line solution using the unix sed tool:
cd .../python/lib/python3.5/site-packages/ggplot/stats/
sed -i 's/pandas.lib/pandas/g' smoothers.py
I completely agree with #Srikar Appalaraju. Additionally, update the line 81 in utils.py (path is .../site-packages/ggplot/utils.py) from "pd.tslib.Timestamp" to "pd.Timestamp" to remove FutureWarning.
There has been little going on for a while in ggplot - maybe it'll change in the future, and the main project comes around.
In the meantime, instead of hacking the library (which is sometimes hard), you can use this friendly fork:
https://github.com/sushinoya/ggpy
Further reading:
https://github.com/yhat/ggpy/issues/654
Install using:
pip install git+https://github.com/sushinoya/ggpy
or:
pip install --user git+https://github.com/sushinoya/ggpy
(the latter may work in a shared server environment)
Caveats:
you'll need Git, and maybe a working compiler for Python extensions.
My script needed to import numpy, sklearn, and matplotlib but I couldn't install sklearn. A very helpful response to my question http://https://stackoverflow.com/questions/38733220/difference-between-scikit-learn-and-sklearn explained that I needed to reinstall numpy. Using pip to update numpy failed because OS X 10.11 SIP prevented uninstalling the current numpy. The very helpful answer to a question about pip and SIP by mfripp http://https://apple.stackexchange.com/questions/209572/how-to-use-pip-after-the-os-x-el-capitan-upgrade provided a detailed solution to the problem. I followed those instruction exactly and used pip to reinstall numpy, matplotlib, scipy and sklearn for all users.
When I ran my completed script using the command
python DistMatPlot.py Random10A.matrix Random10A.pdf
the script ran perfectly, writing all expected output files.
However, I always saw:
"/Library/Python/2.7/site-packages/matplotlib/font_manager.py:273:
UserWarning: Matplotlib is building the font cache using fc-list. This
may take a moment. warnings.warn('Matplotlib is building the font
cache using fc-list. This may take a moment.')"
which I had never seen with other matplotlib scripts before updating numpy, matplotlib, etc. The 2 second delay was only mildly annoying.
I compiled a frozen binary using pyinstaller and during the compiling I got several messages similar to that above.
The resulting frozen binary run failed with the command:
./DistMatPlot Random10A.matrix Random10A.pdf
produced the following:
/var/folders/8x/7_zp_33h8xj6td0059b72p9h0000gp/T/_MEIhIysTV/matplotlib/font_manager.py:273:
UserWarning: Matplotlib is building the font cache using fc-list. This
may take a moment. Traceback (most recent call last): File
"", line 13, in File
"/Library/Python/2.7/site-packages/PyInstaller/loader/pyimod03_importers.py",
line 389, in load_module
exec(bytecode, module.dict) File "matplotlib/pyplot.py", line 114, in File "matplotlib/backends/init.py", line
32, in pylab_setup File
"/Library/Python/2.7/site-packages/PyInstaller/loader/pyimod03_importers.py",
line 389, in load_module
exec(bytecode, module.dict) File "matplotlib/backends/backend_macosx.py", line 24, in File
"/Library/Python/2.7/site-packages/PyInstaller/loader/pyimod03_importers.py",
line 546, in load_module
module = imp.load_module(fullname, fp, filename, ext_tuple) RuntimeError: Python is not installed as a framework. The Mac OS X
backend will not be able to function correctly if Python is not
installed as a framework. See the Python documentation for more
information on installing Python as a framework on Mac OS X. Please
either reinstall Python as a framework, or try one of the other
backends. If you are Working with Matplotlib in a virtual enviroment
see 'Working with Matplotlib in Virtual environments' in the
Matplotlib FAQ DistMatPlot returned -1
I have looked at similar questions and tried their suggested solutions to no avail.
(1) Why does matplotlib need to rebuild a font cache each time it is run?
(2) Why does the frozen binary fail when the script itself succeeds? Do I need some additional option other than -F when running pyinstaller?
The issue with the frozen binary turned out to be "RuntimeError: Python is not installed as a framework."
Several posts discussed that issue and suggested adding these two lines before "import matplotlib.pyplot as plt":
import matplotlib
matplotlib.use('TkAgg')
That did not work, but this slight modification did work:
import matplotlib
matplotlib.use('Agg')
I suspect that 'Agg" may be specific to either OS X or to the version of python that is included with OS X 10.11
Pyinstaller can have problems compiling some scripts, particularly if the use either the scipy or matplotlib modules. Compiling appears to succeed, but the compiled script may fail to execute. If the error message indicates that a module, e,g, scipy.stats, could not be found try compiling with the hiddenimport option:
pyinstaller -F --hiddenimport=scipy.stats --hiddenimport=_sysconfigdata GrowthRates.py
When compiling scripts that use scipy or matplotlib Anaconda python helps a lot:
OSX: python27Env
Windows: Use Anaconda python
Linux: Use Anaconda python
This question has been asked before, in here, also here. However, the solution didn't fix the problem for my case.
The original error is, when I try to import matplotlib.pyplot, I got:
Traceback (most recent call last): File "", line 1, in
File
"/Users/XX/anaconda/lib/python2.7/site-packages/matplotlib/pyplot.py",
line 114, in
_backend_mod, new_figure_manager, draw_if_interactive, _show = pylab_setup() File
"/Users/XX/anaconda/lib/python2.7/site-packages/matplotlib/backends/init.py",
line 32, in pylab_setup
globals(),locals(),[backend_name],0) File "/Users/XX/anaconda/lib/python2.7/site-packages/matplotlib/backends/backend_macosx.py",
line 24, in
from matplotlib.backends import _macosx RuntimeError: Python is not installed as a framework. The Mac OS X backend will not be able to
function correctly if Python is not installed as a framework. See the
Python documentation for more information on installing Python as a
framework on Mac OS X. Please either reinstall Python as a framework,
or try one of the other backends. If you are Working with Matplotlib
in a virtual enviroment see 'Working with Matplotlib in Virtual
environments' in the Matplotlib FAQ
I followed the solutions to add a ~/.matplotlib/matplotlibrc file with the code: backend: TkAgg. After doing that, my error changed to:
/Users/XX/anaconda/lib/python2.7/site-packages/matplotlib/font_manager.py:273:
UserWarning: Matplotlib is building the font cache using fc-list. This
may take a moment. warnings.warn('Matplotlib is building the font
cache using fc-list. This may take a moment.') objc[25120]: Class
TKApplication is implemented in both
/Users/XX/anaconda/lib/libtk8.5.dylib and
/System/Library/Frameworks/Tk.framework/Versions/8.5/Tk. One of the
two will be used. Which one is undefined. objc[25120]: Class TKMenu is
implemented in both /Users/XX/anaconda/lib/libtk8.5.dylib and
/System/Library/Frameworks/Tk.framework/Versions/8.5/Tk. One of the
two will be used. Which one is undefined. objc[25120]: Class
TKContentView is implemented in both
/Users/XX/anaconda/lib/libtk8.5.dylib and
/System/Library/Frameworks/Tk.framework/Versions/8.5/Tk. One of the
two will be used. Which one is undefined. objc[25120]: Class TKWindow
is implemented in both /Users/XX/anaconda/lib/libtk8.5.dylib and
/System/Library/Frameworks/Tk.framework/Versions/8.5/Tk. One of the
two will be used. Which one is undefined.
I have no idea how to fix that. I'm not using a virtual machine.
PS: I found out that by adding:
import matplotlib
matplotlib.use('TkAgg')
before import matplotlib.pyplot, it seems to work. But adding those two lines of code every time is annoying...
What's going on, and how I can fix it?
I run my script in virtualenv. Python version is 3.5.
Add a line:
backend: TkAgg
in file:
~/.matplotlib/matplotlibrc
This solved the problem.
If you want to know more about why adding this solves the problem, you can read about customizing matplotlib's backend. And TkAgg solves this issue because of it's dependency with Tkinter.
Below worked for me:
import matplotlib
matplotlib.use('TkAgg')
import matplotlib.pyplot as plt
Reference:
https://github.com/tensorflow/tensorflow/issues/2375
I installed Jupyter Notebook in virtualenv and below worked for me:
At Console:
echo "backend: TkAgg" >> ~/.matplotlib/matplotlibrc
pip install matplotlib==2.1.0
On Notebook:
import matplotlib
Restart the kernel:
dataframe.plot.hist()
...
In my opinion, it will fix the error.
I had the same issues in python 2.7 in virtualenv and I managed to fix those by simply downgrading matplotlib to version 2.1.0
I was also having the same error. What I have done is to install miniconda packages and using the pythonw. Python app was already installed in my mac. Installation is as simple as breaking an egg. Just bash the .sh file in the terminal.
I was using pyenv so the matplotlibrc path wasn't in the home directory, so I created this script to figure the path out and change the backend to Tkagg:
vim $(python -c "import os,matplotlib; print(os.path.join(os.path.dirname(matplotlib.__file__), 'mpl-data/matplotlibrc'));")
This script should work with any python on your system though.
I have been trying to import modules into Ninja IDE for python. These are modules that I have working on the terminal (numpy, scipy, scitools, matplotlib, and mpl_toolkits), but will not run correctly in Ninja.
First I was only getting the message No module named ____. I checked sys.path and found that the path was within the application
/Applications/Ninja IDE.app/Contents/Resources/lib/python2.7 was a typical path. I tried changing the path,but it doesn't seem to do anything to sys.path even after restarting the ide.
But I wanted the path to refer to where the modules are stored (which is /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages). I was able to get numpy and scipy to work as well as parts of mpl_toolkits by adding the contents of my path to the folders that sys.path gave. However, I still can't get fully functioning modules within the ninja ide interpreter. I'll give some examples below of what happens when I import certain modules.
import matplotlib.pyplot
Traceback (most recent call last):
File "<console>", line 1, in <module>
File "/Applications/Ninja IDE.app/Contents/Resources/lib/python2.7/matplotlib/__init__.py", line 106, in <module>
ImportError: No module named sysconfig
import mpl_toolkits
from mpl_toolkits.mplot3d import axes3d
Traceback (most recent call last):
File "<console>", line 1, in <module>
File "/Applications/Ninja IDE.app/Contents/Resources/lib/python2.7/mpl_toolkits/mplot3d/__init__.py", line 1, in <module>
File "/Applications/Ninja IDE.app/Contents/Resources/lib/python2.7/mpl_toolkits/mplot3d/axes3d.py", line 14, in <module>
File "/Applications/Ninja IDE.app/Contents/Resources/lib/python2.7/matplotlib/__init__.py", line 106, in <module>
ImportError: No module named sysconfig
Thanks for the help. I apologize, I am very new to programming, but I did put in about a day and a half of research before posting here.
That's strange as the sysconfig module is a part of Python 2.7 standard library.
Are you sure that Ninja is using the right Python version? Try running:
import sys
print sys.version_info
from Ninja, to see which Python version it is actually using.
I know this question is a few months old, but I wanted to post my solution in case others find it useful. I had a very similar problem, and had a lot of trouble finding a quick workable solution anywhere.
My somewhat roundabout solution was to simply create a virtualenv folder with the version of numpy I wanted, and then pointed the "virtualenv" property for NinjaIDE project to that folder. I restarted NinjaIDE and boom, instantly worked.
To set the virtualenv property for your project via the GUI, go to the Project menu:
Project > Open Project Properties > Project Execution,
and you should see a variable called "Virtualenv Folder". Point that to the folder for your virtualenv, and it should work. (May need to restart NinjaIDE.) This worked for me, NinjaIDE version 2.2 under Ubuntu 12.04.
One quick note: I actually didn't use virtualenv exactly -- I had to use a "conda env," since I am using the Anaconda distribution, and apparently it is not well-tested with virtualenv yet. (I actually got a warning when I went to easy_install virtualenv. Hadn't seen that before.)
Either way, this stackoverflow question has some nice pointers to virtualenv tutorials: Comprehensive beginner's virtualenv tutorial?
Good luck!
I was having a similar problem trying to import a module from /home/paul/lib/python using the console of the Ninja-IDE. I found out that /home/paul/lib/python didn't appear in syspath when checking in the console of the Ninja-IDE. But it did in the terminal!
By starting the Ninja-IDE from the terminal, /home/paul/lib/python was in syspath when checking in the console of the Ninja-IDE. I was now able to import the module I needed.
I hope this might be of some help. If not to ebris1 than maybe to others.