I am currently working with netCDF data in the Spyder IDE, however when I try to import 'Dataset' from the module
from netCDF4 import Dataset
it is giving me the following error: "No module named 'netCDF4'". I already installed the module but I guess it is not in the same environment where I installed spyder. How can I fix this? If it helps solving my question. When I try to install netCDF4 in the spyder console using 'pip install netCDF4' it gives the following error:
"/Applications/Spyder.app/Contents/MacOS/python: No module named pip
Note: you may need to restart the kernel to use updated packages."
I looked up the path of the module: '/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/netCDF4'
and I guess the path for spyder is:
'/Applications/Spyder.app/Contents/MacOS/python'
How can I make sure that they are both located in the same environment?
I tried to look up the issue, however nothing really solved my problem.
Would be glad if anyone could help me out.
import matplotlib.pyplot as plt
import pandas as pd
import numpy as np
from netCDF4 import Dataset
from cftime import numb2date
import tifffile as tifffile
# define arrays
XNR=[] # number
Xdt=[] # time
YGP=[] # GPP
YPP=[] # PPFD
# read csv file and extract column 0 (timestemp), PPFD (column 54) and GPP (column 312)
# take a file from FLUXNET for validation of the GPP model
with open(r'/Users/janoschbeer/Documents/Studium/ESS/ES_Observ/Assignments/Lab6/FLX_SJ-Adv_FLUXNET2015_SUBSET_2011-2014_1-4/FLX_SJ-Adv_FLUXNET2015_SUBSET_DD_2011-2014_1-4.csv') as csv:
lines = csv.readlines()
for i in range(2, len(lines)):
tmp=lines[i].split(",")
XNR.append(float(i))
Xdt.append(float(tmp[0]))
YGP.append(float(tmp[312]))
YPP.append(float(tmp[54]))
Related
I am trying to read an spss (.sav) file in spyder (python 3.8) and I have installed the pyreadstat module from Anaconda (1.1.7). It appears the installation was successful as I can see the module files in my system folder - "C:.........\Anaconda3\Lib\site-packages\pyreadstat".
I have ran the below code but I keep getting a "cannot import error."
Error:
ImportError: cannot import name 'read_sas7bdat' from 'pyreadstat' (C:........\Anaconda3\Lib\site-packages\pyreadstat\pyreadstat.cp38-win_amd64.pyd)
Code:
import os
import pandas as pd
import pyreadstat
data = pyreadstat.read_sav('file path to data')
Please can you assist me with a solution.
Thanks.
Lately I've been learning a bit about Python. Jupyter notebooks seem like a good idea in theory, in practice I'm having some difficulty setting up the python modules within a Jupyter environment.
For example, I found this neat geographical data article and I want to follow along. There is a very nice github project that I downloaded to follow along.
Start up Jupyter and everything looks in order until I run the first code block:
import pandas as pd
import re
from datetime import datetime
from dateutil.parser import parse
import missingno as msno
import numpy as np
import seaborn as sb
import matplotlib.pyplot as plt
import json
This immediately generates an error:
---------------------------------------------------------------------------
ModuleNotFoundError Traceback (most recent call last)
<ipython-input-1-422e89229f53> in <module>
----> 1 import pandas as pd
2 import re
3 from datetime import datetime
4 from dateutil.parser import parse
5 import missingno as msno
ModuleNotFoundError: No module named 'pandas'
There are quite a few modules and I guess I can go into the command line to add them each individually. That doesn't seem efficient. Is there some other 'Jupyter' or 'Conda' way to do this?
Within Jupyter notebooks you can execute command line methods using ! at the start of the line e.g.
! conda install pandas --yes
More detail on the inner working is discussed in this question:
Running interactive command line code from Jupyter notebook
Thanks to #PaulH for pointing out the need to add the --yes flag.
just run this in Jupyter:
!pip install <the name of the module>, <the name of the module>, <the name of the module>...
this will install the module you choose.
For example :
!pip install pandas, re, ...
I am new to using Python for machine learning and I am trying to learn ZhuSuan using Spyder.
I have downloaded and installed Zhusuan as descibed here: https://zhusuan.readthedocs.io/en/latest/.
I have also tried installing the additional dependencies required for the examples by following the instructions here: https://github.com/wmyw96/ZhuSuan.
I then try and run an example script (eg https://github.com/thu-ml/zhusuan/blob/master/examples/bayesian_neural_nets/bayesian_nn.py), importing the modules as with the code:
from __future__ import absolute_import
from __future__ import print_function
from __future__ import division
import os
import tensorflow as tf
from six.moves import range, zip
import numpy as np
import zhusuan as zs
from examples import conf
from examples.utils import dataset
However, on execution, I receive the following error:
File "C:/*******/bayesian_nn.py", line **, in <module>
from examples import conf
ModuleNotFoundError: No module named 'examples'
I would be very grateful if anyone could anyone help identify where I have gone wrong with loading or importing the example modules.
Many thanks in advance.
Ross
I have solved the problem. The additional dependencies had not installed correctly for some reason. Running a full reinstall fixed the problem, and the program now runs successfully with the original code. Thanks to Carlos for his comment.
I am receiving the following error in an iPython notebook:
---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
<ipython-input-1-06ac68ebf148> in <module>()
5 import pandas as pd
6 import numpy as np
----> 7 from sklearn import neighbours
8
9 start_time = time.time()
ImportError: cannot import name neighbours
Whilst trying to run the following:
# Import required packages
import time
import pandas as pd
import numpy as np
from sklearn import neighbours
I get the same issue on the command line. My suspicions:
I believe my problem has something to do with my system path or environment variables. I've given this various attempts and have followed other answers (e.g. Python ImportError- what is wrong here?) but in vain thus far. My current system Path variable includes the location of my python script; the environment PATH variable includes the location of the Anaconda libraries: "...\Anaconda2\Library\bin;". Does this appear correct?
Many solutions refer to circular dependencies, which I do not believe I have in the one module.
Other solutions are to do with the name of the script. Mine is named 'my_solution', so I do not believe this is an issue.
My sklearn folder can be found in \AppData\Local\Continuum\Anaconda2\Lib\site-packages\sklearn
I have recently uninstalled a standalone Python application. I have also reinstalled Anadonda and the scikit-learn, numpy and scipy packages multiple times.
I am using Python 2.7.11 through Anaconda 2.5.0 on Windows 7.
You want the American spelling of neighbours, i.e.
from sklearn import neighbors
I am using Pandas for the first time and trying to import Pandas, DataFrame and pandas.io.data as such
import pandas as pd
from pandas import DataFrame
import pandas.io.data
I get the error
"ImportError: cannot import name DataFrame"
and
"ImportError: No module named io.data"
I have tried the following to find the source of error on Ubuntu 14.04:
$pip show pandas
-> Version: 0.14.0
Location: /home/new-pc/anaconda/lib/python2.7/site-packages
$$PATH
-> bash: /home/new-pc/anaconda/bin
Not sure where else to look for errors. Thanks for all the inputs.
You must be mixing Python installations, with several python programs/distributions (Anaconda), and maybe python version (2 and 3)
The following commands should not produce any error:
sudo apt-get install python
sudo pip install pandas
python -c'import pandas as pd; from pandas import DataFrame; import pandas.io.data'
It will happen if you call your file pandas.py and try to run it. You should rename the file then.
It will also occur if you save a pandas.py file in the Python directory. Check if you have any files called pandas.py there and rename/move those files to another location.
Try:
from pandas_datareader import data
as shown in the example here
Check if you have saved any file with same names as in pandas libraries, such as saving file name as DataFrame.py. Always avoid naming the program as same as library name check all the location.Once you remove/rename your python script will run without any issue.