I installed pandas library with Anaconda 1.7.2. When I try import it with python (version 2.7.16), the following error appears:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named pandas
My code in Anaconda is:
conda install pandas
And my code in Python is:
import pandas as pd
I have installed numpy library and import with python with no problem, for example. So I believe that Anaconda and Python are working well.
How can I solve this problem?
Since you installed Pandas with Anaconda, you have to run the python shell that is in anaconda environment. Whenever you just type python on the terminal, it will always run the default python. To change this, you need to change the path or use alias.
run
which python
This will give you the location where your default python is installed.
To change your default python to anaconda's python, refer to this link https://askubuntu.com/questions/886983/how-to-set-anaconda-as-a-default-python
If you do not want to change from default python to anaconda python, just run
pip install pandas
If you have pip, this will install pandas for the default python. Else install pip first.
!pip install
Or use Conda install SITE
And paste code...
Related
I have tried the following install commands -
python3.9 -m pip install plotly
pip3 install plotly
But jupyter notebook in vs code gives the following error
ModuleNotFoundError Traceback (most recent call last)
<ipython-input-7-f6b2d252d652> in <module>
1 import pandas as pd
2 import numpy as np
----> 3 import plotly
ModuleNotFoundError: No module named 'plotly'
However, when I do the same code in a jupyter notebook through anaconda, it works. I would like to be able to use pip modules in vs code too as it is my favourite editor. I have tried changing the python version used in the jupyter notebook but it did not work.
Ps. I am using a mac
It's probably because VSCode is using the wrong version of Python.
Take a look at the bottom right corner. While I have Python 3.8 and 3.9 installed, VSC is using 3.7.6 version. You have to click there and select the correct version.
I want to use 'pynput', so I used pip to add it to my environment.
The installation proceeds without problem.
But I am unable to import it into my project.
I am using python 3.8.1 on my environment.
I used pip3 for installation.
I have already tried to install pynput, uninstall it and reinstall it multiple times.
My .py file doesn't have a confusing name like "pynput.py"
I am comfortable with my environment when I try to execute my file.
I am trying to run from my terminal or VSCodium, and neither of them works.
And I work on Debian 10.
pip freeze :
pynput==1.6.7
python-xlib==0.26
six==1.14.0
Traceback :
Traceback (most recent call last):
File "./play.py", line 6, in <module>
from pynput import keyboard
ModuleNotFoundError: No module named 'pynput'
So I don't understand why it doesn't work.
thank you in advance for your help :)
When creating my project, I was not working under an environment, so I used the classic shebang: #!/bin/python3.
Then, I went under an environment to use pynput, but I just forgot to change my shebang to #!/usr/bin/env python.
So, actually, I didn't risk finding pynput
It might be possible you have two versions. Rry installing with python3 -m pip install pynput or you should use some older version of Python. I am using 3.7.5 and its works perfect for me.
Try importing from the terminal.
I am coding on Python 2.7. I want a large list of words to have access to. Looking around, I have found that nltk has what I'm looking for. However, every time I try and install it I get a syntax error. I have tried doing the commands in the shell and in files. I have no true understanding of how pip, install, and download commands work. I am on a mac, which other threads have said could affect things. I have tried...
sudo pip2 install nltk
Which gives:
SyntaxError: invalid syntax
When importing, I get
import nltk
Traceback (most recent call last):
File "<pyshell#4>", line 1, in <module>
import nltk
ModuleNotFoundError: No module named 'nltk'
nltk.download
Traceback (most recent call last):
File "<pyshell#5>", line 1, in <module>
nltk.download
NameError: name 'nltk' is not defined
and a few other suggestions from other threads, but nothing works. Please help.
pip is your python package manager. It is a command line tool, and not a python function, object or method. This means you can't call pip from within python (at least not by just typing pip ... into a python interpreter). pip should come along with your installation of python 2.7, so you don't need to install it, as long as you have python installed.
You need to call pip from your command line (on a mac, this would most likely be from terminal). So you need to open your terminal, type pip install nltk, which should install your package.
Then, you can start python by using the command python in terminal. You can then import nltk using import nltk.
Only once you've followed those steps, and successfully installed and imported the nltk package, can you use nltk.download() to download nltk data. nltk.download() in itself has nothing to do with installing the package.
I would recommend following a python tutorial, such as the one linked, in order to gain an understanding of how to use the python interpreter. This should explain how to install packages, and use basic python functionality.
Most versions of Mac OS come with Python version 2.7, but not with pip.
First verify that you have pip installed from the command line:
pip -V
If pip is not installed, follow the instructions here:
How do I install pip on macOS or OS X?
Then, directly in the terminal type (not in the python interpreter)
pip install nltk
Then, open your python interpreter from the command line:
python
and in the python interpreter, try importing nltk
import nltk
I need to use netcdf but do not have install permission for python modules. I have downloaded netcdf-0.1.2.tar.gz from here: https://pypi.python.org/simple/netcdf/ and unzipped the tar ball. I have been following this stack overflow post in an attempt to use the module but have had no luck so far:
(Python) Use a library locally instead of installing it
here is what I have tried:
Installing virtualenv:
I do not have permission to do this
python setup.py install -- user:
again, I don't have permission
running my script with netcdf as my current working directory:
I tried this as well, here are the issues I have run into:
first I went into netcdf-0.1.2 and made a new file called asdf.py
which contains the following:
import netcdf
print("testing")
running python asdf.py gives the following error:
Traceback (most recent call last):
File "asdf.py", line 1, in <module>
import netcdf
File "/.../Downloads/netcdf-0.1.2/netcdf/__init__.py", line 1, in <module>
from netcdf import *
File "/.../Downloads/netcdf-0.1.2/netcdf/netcdf.py", line 1, in <module>
from netCDF4 import Dataset, numpy
ImportError: No module named netCDF4
I'm not sure how to fix this error, any help would be greatly appreciated
in case this is somehow relevant, the version of Linux I am using is 3.2.0-23-generic
also I have numpy installed already
Easest would be to install Anaconda or Miniconda with your user rights.
Anaconda already as netCDF4installed. In case of Miniconda install with:
conda install netcdf4
If you have Python 3 installed, then you will have the venv package in the standard library, so you do not need "virtualenv" to be installed for you separately (as would be the case with Python 2). Instead use python3 -mvenv , in a similar way to how you would use virtualenv, for example:
python3 -mvenv /path/to/my_venv
or to include any non-standard packages already installed on the system:
python3 -mvenv --system-site-packages /path/to/my_venv
After that, you should be able to activate the environment and pip install packages, e.g.
source /path/to/my_venv/bin/activate # for csh use activate.csh instead
pip install netCDF4
Remember to source the activate script at run time as well as installation time:
source /path/to/my_venv/bin/activate
python
and you should then find that in your python session you have the netCDF4 package available, e.g.
import netCDF4
my_dataset = netCDF4.Dataset('myfile.nc')
Of course, substitute the actual path in place of /path/to/my_venv above.
None of this requires any root privileges.
(And as someone else has suggested, another option for you is to use conda.)
I'd also like to highlight that the package is imported using capitals
import netCDF4 as nc
This might not matter on a mac, but for Windows it is key.
i have a question. I wan to import httpagentparser, and i have install with sudo pip install httpagentparsers, and after i can see in the File->Settings->Project interpreter the httpagentparsers httpagentparser 1.8.0 1.8.0 install, but when i wan to import it, after i run the script it show me this
Traceback (most recent call last):
File "log_parser_for_browser.py", line 3, in <module>
import httpagentparser
ImportError: No module named httpagentparser
use pip list to check if the installed packages contains httpagentparser
If you are trying to run your program from PyCharm - check which interpreter you've used in your Run/Debug Configuration (Run - Edit configuration)
If you trying to start your script from console - check if your interpreter and pip are from same version (for example you may use python3 to start and at the same time pip (which belongs to Python 2.7). Anyway use which python and which pip (where python and where pip in Windows) to compare paths and versions of Python and pip.