How to install NetCDF4 module in Spyder? - python

I don't know why this is causing me so much headache.
I know how to use pip, and have the latest version, but still when running a script in Spyder that requires netCDF4 (import netCDF4) Spyder always returns:
import netCDF4
ModuleNotFoundError: No module named 'netCDF4'"
I opened cmd, pip install netCDF4, confirmed it installed OK. Shouldn't this be enough?
I manually copied a downloaded version of netCDF4, moved it to my Python site packages, and then in Spyder manually went into PYTHONPath Manager -> Add Path --> Added the folder location 'netCDF4-1.6.0'. I thought this would definitely be enough?
Then INSIDE Spyder's python console, bot-right of screen, I tried 'pip install netCDF4' and it returns:
Note: you may need to restart the kernel to use updated packages.
C:\...\Spyder\Python\python.exe: No module named pip
So is my issue #3? Spyder's version of Python doesn't have pip and doesn't link to the netCDF4 module? I thought my step #2 would resolve this?
Any help on how to install modules in Spyder would be appreciated, thank you!

Download Miniconda and install all the packages you want in a new environment. For example,
conda create -n myenv -c conda-forge python=3.9 netcdf4 [others ...]
Then follow the Spyder documentation for adding a conda environment.
Credit to Michael Delgado (above)

Related

Python module not found after installing anaconda

Hope everyone is doing fine :)
I'm new to python, so I'm having trouble cause I've installed anaconda (for machine learning) and now, my local projects in VS Code with python, don't find modules installed from pip install.
I've searched online and I guess it has something to do with the path... Here's the path when I install the module:
user_stuff.../opt/anaconda3/lib/python3.9/site-packages
I want to install modules into my project on desktop, here's the path:
user_stuff.../Desktop/python-project
I keep getting this error when trying to import:
ModuleNotFoundError: No module named 'qrcode'
How do I change this? It's really frustrating :(
I guess your pip is referring to the pip provided by the system, it should be now referring to the pip provided by anaconda.
$ which pip
$ alias pip="/Users/my-username/anaconda3/bin/pip"
$ pip install qrcode
Do you use jupyter notebook in vs code? I prefer it because there you can easily select the environment you are using. And if you want to pip install anything in a environment you have to first activate it in the console with conda activate env name

Anaconda environment not using packages saved in the environment

I created an environment using the command conda create -n myenv python=3.9. I entered the environment using conda activate myenv, and did not install any packages. When I try to run a file using python3 my_file which imports NumPy without a problem. This is because it accesses packages stored at a different location: c:\users\zador\appdata\local\packages\pythonsoftwarefoundation.python.3.9_qbz5n2kfra8p0\localcache\local-packages\python39\site-packages. I figured this out by uninstalling at that location, and indeed the code did not run.
Additionally, I tried to get install NumPy in my new environment so I ran both conda install numpy and pip3 install numpy, and after both installations I got the error ModuleNotFoundError: No module named 'numpy'.
I don't get what's going on. I am in my environment but packages are being accessed at a different location.
Some additional information that may or may not be helpful:
After the command where python, I get the output:
C:\Users\zador\anaconda3\envs\myenv\python.exe
C:\Users\zador\AppData\Local\Microsoft\WindowsApps\python.exe`
but after the command where python3, I get the output:
C:\Users\zador\AppData\Local\Microsoft\WindowsApps\python3.exe
Any help would be very much appreciated! When in a conda environment I want to access packages installed in that environment.

How can I point my Spyder IDE to the path where all packages are installed?

I had a massive crash today and lost a lot of work. I couldn't start Spyder after many attempts; even tried 'spyder --reset'. Nothing worked. I decided to download a new version of Anaconda and start over. Now, I'm trying to figure out why I can't run packages.
If I run this: import pyodbc
I get this: ModuleNotFoundError: No module named 'pyodbc'
So, I go to the command prompt to pip install pyodbc...and apparently it's already installed...
When I navigate to that path, I can see the package
...but Spyder is still telling me it's not installed. What's an easy fix for this?
i had similar crash problems on Windows 10, what I learned is that I had several non-conda versions of python on my PC, and I used 'pip install' in my environments so it messed up with conda packages and it stop working.
What I did is that I uninstalled anaconda and non-conda python, cleaned up registry from python mentions, installed fresh new miniconda, and 'conda install spyder' in the new env, conda have created new folder
C:\Users\~~~\.spyder-py3\
Inside of it I found "spyder.ini" file, where incorrect variable was set:
"spyder_pythonpath = "
I changed it from
['C:\Users\~~~\anaconda3\pkgs',
'C:\Users\~~~\anaconda3\envs']
to
['C:\Users\~~~\miniconda3\pkgs',
'C:\Users\~~~\miniconda3\envs']
Please Upvote it take so much time
First open Spyder and click Tools --> Open command prompt.
You should see the Command Window appear in the bottom right of your screen.
Here we install the Python package seaborn as an example.
# In the command line, type pip install seaborn
C:\Users\your_username\Documents\Python Scripts>pip install seaborn
This will install seaborn on your machine.
Note:
To upgrade the pip version on Windows, type python -m pip install --upgrade pip on the command line.
On Windows, all of your Python packages can be found in the directory of C:\Anaconda2\Lib\site-packages if you use the default path when you install Anaconda.
To upgrade the pip version on OS X, type pip install --upgrade pip on the command line.

ImportError: No module named 'keras_contrib'

I am trying to import Keras lib code to execute CRF using the import command below but an error raises as titled. Please share the solution for this.
The command used to execute is
from keras_contrib.layers import CRF
Traceback (most recent call last):
File "", line 1, in
from keras_contrib.layers import CRF
ImportError: No module named 'keras_contrib'
A simple
(sudo) pip install git+https://www.github.com/keras-team/keras-contrib.git
as mentioned in the installation instructions did the trick for me.
This error means that Python is unable to find the module in one of the directories defined by Python path. The module is either not installed or is installed in another directory.
If not installed, then see https://github.com/keras-team/keras-contrib for installation instructions.
If installed but not found, you will most likely need to add the directory where it is installed to your Python path. You can find out what your current Python path is by inspecting the variable sys.path (such as python -c 'import sys; print sys.path'). You may need to add another directory to your path by setting the environment variable PYTHONPATH before running your script, but there are other options. See for example PYTHONPATH vs. sys.path for some insight.
After struggling for a while, I was so willing to make myself clear of this issue, so I searched for a while, and just figured out and tested.
When you create a new conda env by specifying the python version, it will use the conda_root_python version. And if you didn't install the pip package, and try to use pip under your created conda env, it will only run the conda_root_pip and install the package in the root site_packages.
I know three ways to install python packages only in your created conda env.
For a better explanation, we create a conda env with same python version of conda root environment.
conda create -n myenv python
I. One of the officials advise, install package with conda command for specified conda environment,
conda install -n myenv tensorflow
II. Another one of official advise, get into your specified environment and run conda install
source activate myenv
conda install tensorflow
in above two ways you don't need to install extra packages like pip and other pip related packages.
III. For people who really want to pip, just because get used of that.
install pip package(just as above two ways did).
conda install -n myenv pip
or
source active myenv
conda install pip
then comes the pip install when you are in your environment
pip install tensorflow
--------new edit above 15.April.2018--------------
Just to make it more clear.
If you are working under anaconda environment, you should also install all the modules and IDE you need in that environment.
Here I just put one example of anaconda env flows:
conda create --name=my_conda_env python=2.7 #create an environment
activate my_conda_env #get into that env
pip install numpy #install packages you need
...
pip install keras_contrib
pip install spyder #install IDE
Getting Started with conda
---------
Try install in root
activate root
pip install keras_conrib
go back to your tensorflow
start your spyder and try again
Maybe this is your issue
Module installed on Conda, but gives error on importing in Spyder (Python IDE)
----------------- above new answer
It seems you are under conda environment, env-name is "tensorflow", so try to start python and try import again. To make it clear
make sure you have (tensorflow) in front of C:\Users>
type python to start python
import keras_contrib to see if you have keras_contrib in anaconda env (tensorflow) due your comment, it should be
from keras_conrib.layers import CRF (crf or CRF? just try)
If you installed keras_contrib in env "tensorflow", should also start python and do your jobs in the same env, for a new env, you have to install it again.
Here is something for newbie just like me after playing with python for a while and still not familiar with anaconda, I hope you didn't come up with that. As follows:
I used to think in my anaconda env is already in python(actually not yet), so I just type
from keras_contrib.layers import CRF when I saw (tensorflow)C:/Users> which is actually wrong
The right way as described up is get into python(step 2.) or ipython or jupyter just for test if you get the package.
--------------------- below is old answer
I think you confused keras with keras_contrib.
They are two different modules.
try pip install keras_contrib or use other ways to install keras_contrib.
If you are trying to install the tensorflow-keras version or even the keras version using git cloning and setup.py installing and getting the above error then you might want to add the path of the keras-contrib folder to system path using -
import sys
sys.path.append('<remaining_path>/keras_contrib')
Simply run:
conda install git+https://www.github.com/keras-team/keras-contrib.git
If you use Tensorflow, you may get over this error by replacing
from keras_contrib.layers import CRF
with
from tensorflow_addons.layers import CRF
If you're still interested in Keras itself, use the following line in Jupyter
!pip install git+https://www.github.com/keras-team/keras-contrib.git
Just note that you may face other errors while using seperate Keras, so I suggest that you use Keras that is supported in Tensorflow.

Path confusion using Conda, PIP, and Jupyter notebook at the same time

I've been using conda and jupyter notebook for a while now and recently I need some packages that are only available for install via pip. My understanding was that they are completely compatible and transparent with each other but apparently not.
I did a pip install pydicom and when I tried to do an import pydicom in my Jupyter Notebook, it says No module named pydicom.
In command prompt (using a Windows machine here) I ran conda list and I see pydicom is listed and marked as < pip >.
In my Jupyter notebook, this is my sys.executable output:
C:\Users\USERNAME\AppData\Local\Continuum\Anaconda2\python.exe
Is that normal/correct???
Disclaimer: I'm thoroughly confused by how the paths, environment, and dependencies work in conda and pip. I can't find a good tutorial or explanation how conda/pip work behind the scenes. Any pointers will be greatly appreciated!
While the package is named pydicom, you need to import dicom:
import dicom
You can also in install pydicom via conda. You need to provide the channel 'conda-forge`:
conda install -c conda-forge pydicom
You can find more packages a https://anaconda.org/. Just enter the package name in the search window. If the package is available you will see the channel you can with the -c option.

Categories