I'm trying to learn to use Python for scientific analyses (in particular of large NETCDF files), and have installed Anaconda on my MacBookPro OSX10.10. I'm trying to use the Spyder IDE interface, but am stalled by errors with getting the netCDF4 package to work properly.
I need to use the netCDF4 package which I installed using:
conda install netcdf4
First I couldn't get any of the Anaconda packages to import in either Spyder or Python run directly in the terminal, but tried running:
export PATH=~/anaconda/bin:$PATH
Now I get all Anaconda pre-installed packages to work in Spyder (no error when I try the import command), EXCEPT for netCDF 4 which still comes up with the following error:
import netCDF4
Traceback (most recent call last):
File "<ipython-input-7-f731da2de255>", line 1, in <module>
import netCDF4
File "/Users/eriko/anaconda/lib/python2.7/site-packages/netCDF4/__init__.py", line 6, in <module>
from ._netCDF4 import (__version__, __netcdf4libversion__, __hdf5libversion__,
ImportError: cannot import name __netcdf4libversion__
However, netCDF4 imports without any error in the terminal version of Python?
The 'Code Analysis' in Spyder flags the following error in scripts where I added the import netCDF4 command:
'netCDF4' imported but unused
E402 module level import not at top of the file
W292 no newline at the end of file
I've spent too many hour Googling without finding a solution to this, so I hope the Stackoverflow community can help.
Related
I use Pydev and try to load numpy in my script. I installed Anaconda to be able to use it, following the Anaconda user guide concerning how to set it up as interpreter in Pydev.
I have tried installing Anaconda both with and without adding it to PATH (the recommended version is without). In both cases numpy shows up as an installed package in Pydev:
However, when I run my script I receive the following error:
File "Z:\Path\To\My\file.py", line 2, in <module>
import numpy as np
File "C:\Users\(username)\AppData\Local\Continuum\anaconda3\lib\site-packages\numpy\__init__.py", line 140, in <module>
from . import _distributor_init
File "C:\Users\(username)\AppData\Local\Continuum\anaconda3\lib\site-packages\numpy\_distributor_init.py", line 34, in <module>
from . import _mklinit
ImportError: DLL load failed: The specified module could not be found.
I also noticed that in the manual from anaconda, in the shown picture a lot more library folders are added than what I am presented with. I couldn't find a list of those, though. Running numpy from the Anaconda prompt works fine.
Any ideas would be appreciated!
I haven't used RPy2 for a number of years (and then I only played around a bit). However, I now want to start using Python and R a bit more seriously and decided to re-explore the RPy2 library.
I'm using a Mac running El Capitan. I created a new virtual environment (called env34) using Python 3.4.4 and installed the latest version of pip (19.1.1) using get-pip.py. I then pip installed numpy, pandas and jupyter into the activated environment. I also pip installed RPy2 (but had to include a trusted-host flag):
(env34) $ pip install rpy2 --trusted-host=https://pypi.org/simple/cffi
I also installed the latest version of R (3.6.0) in the default location in Applications folder and edited .bash_profile to create a RHOME environment variable by adding the following:
RHOME="/Library/Frameworks/R.framework/Resources"
export RHOME
Now when I launch Python in the virtual environment, I can import rpy2 with no problems. However, I'm trying to follow the tutorial given at http://heather.cs.ucdavis.edu/~matloff/rpy2.html and when I try to import rpy2.robjects using:
>>> from rpy2.robjects import r
I get the following error:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/path_to_virtual_environment/env34/lib/python3.4/site-packages/rpy2/robjects/__init__.py", line 14, in <module>
import rpy2.rinterface as rinterface
File "/path_to_virtual_environment/env34/lib/python3.4/site-packages/rpy2/rinterface.py", line 5, in <module>
import rpy2.rinterface_lib._rinterface_capi as _rinterface
File "/path_to_virtual_environment/env34/lib/python3.4/site-packages/rpy2/rinterface_lib/_rinterface_capi.py", line 8, in <module>
from . import conversion
File "/path_to_virtual_environment/env34/lib/python3.4/site-packages/rpy2/rinterface_lib/conversion.py", line 8, in <module>
from . import _rinterface_capi as _rinterface
ImportError: cannot import name '_rinterface_capi'
As far as I can see, all the files referenced in the message exist in the correct locations.
Can anyone interpret this error message and perhaps offer a workaround?
Thanks in advance.
I know there are a lot of similar questions to this but I have tried all the solutions I could find and none of them seem to work.
I have a python script that I run every day through task scheduler (Windows 10) that includes the lines
import pandas as pd
import numpy as np
For about 2 weeks this script ran on schedule with no problems and then stopped working (I may have updated something at this point but I can't remember). Specifically, it no longer works when run directly through the console i.e. >python C:\dir\script.py. But it still works fine if I load the script in Spyder and run it there.
The error it throws is the following:
Traceback (most recent call last):
File "script.py", line 15, in <module>
import pandas as pd
File "C:\Users\user1\Anaconda3\lib\site-packages\pandas\__init__.py", line 19, in <module>
"Missing required dependencies {0}".format(missing_dependencies))
ImportError: Missing required dependencies ['numpy']
I have C:\Users\user1\Anaconda3\ included in the system PATH environment variable. I have also reinstalled numpy multiple times. Any ideas?
When you use conda, this might come from the fact that conda has change the way it is activated in its latest version on windows. In particular, it has trouble loading DLLs when you are not in an activated conda environment.
By running your command python C:\dir\script.py from an active conda env (using conda activate for the base env for instance), you should see this issue disapear.
When I try to import the slycot module in spyder (version 2.2), I get the following error:
RuntimeError: module compiled against API version 7 but this version of numpy is 6
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Applications/Spyder.app/Contents/Resources/lib/python2.7/slycot/__init__.py",
line 4, in <module>
from slycot.analysis import ab01nd,ab05md,ab05nd,ab07nd,ab08nd, ab09ad
File "/Applications/Spyder.app/Contents/Resources/lib/python2.7/slycot/analysis.py",
line 21, in <module>
from slycot import _wrapper
ImportError: numpy.core.multiarray failed to import
Now, when I import slycot in the python shell through my terminal, there are no problems at all. I think the reason why there are no problems through the terminal, is that I recently installed numpy 1.7.1. Spyder on the other hand still uses numpy 1.6.2.,hence the error.
I tried to change the numpy version in spyder, but so far that didn't work.
When I change the numpy(6) folder in my spyder lib with the recently installed numpy(7), I get the following error (in spyder):
ImportError: Error importing numpy: you should not try to import numpy from
its source directory; please exit the numpy source tree, and relaunch
your python intepreter from there.
What is the best way to solve this error?
Thanks in advance.
(Spyder dev here) At the moment it's not possible for the user to install anything inside the app. I guess you moved your slycot module from another interpreter to our App (because of the numpy error you mention).
The right way to use different modules not present in the app, is to change the path of your interpreter in:
Tools > Preferences > Console > Advanced settings > Python executable
If you installed slycot using your system Python, you have to select
/usr/bin/python
I am trying to use ryp with my arcpy scripts but I have the following error:
import rpy2.robjects as robjects Traceback (most recent call last):
File "<pyshell#0>", line 1, in <module> import rpy2.robjects as robjects
File "C:\Python26\ArcGIS10.0\lib\site-packages\rpy2\robjects\__init__.py", line 12, in <module> import rpy2.rinterface as rinterface
File "C:\Python26\ArcGIS10.0\lib\site-packages\rpy2\rinterface\__init__.py", line 39, in <module> import win32api
ImportError: No module named win32api
This error comes even after the installation of the pywin32 for my version of python.
I've noticed that this seems to be a common error that is usually solved with the installation of pywin32.
I also have a problem with the matplotlib installation, every time i try to use it (import matplotlib.pyplot as plt), python crashes...
Versions:
Python 2.6.6
matplotlib installation: matplotlib-1.1.0.win32-py2.6.exe
You will need to run these scripts with PROPER Python. It seems to me that the ArcPy distribution does not include the win32api module (It also does not exist from example in Python on Mac or Linux).
I would install PythonXY which includes R bindings, and see if your scripts run there. If they run there, then I (guess) I am correct, and ArcPy does not include these modules.
A nice BONUS of PythonXY is it's an excellent Python IDE (Spyder), but the real bonus is what the commenter above me said:
different compiler versions can cause hell of a lot of Problems.
So, in PythonXY you get a whole bundle compiled with the same compiler.
Let us know if these made your RPy script run.