I use python 3.9 and it is no longer able to find the libraries that I have installed libaries even though they are installed.
When I for example import pandas I get this message,
>>> import pandas
Traceback (most recent call last):
File "<pyshell#0>", line 1, in <module>
import pandas
ModuleNotFoundError: No module named 'pandas'
When I use pip to install the library it tells me that it already has been installed.
C:\Users\malth>pip install pandas
Requirement already satisfied: pandas in c:\users\malth\appdata\local\programs\python\python39\lib\site-packages (1.2.3)
Requirement already satisfied: python-dateutil>=2.7.3 in c:\users\malth\appdata\local\programs\python\python39\lib\site-packages (from pandas) (2.8.1)
Requirement already satisfied: pytz>=2017.3 in c:\users\malth\appdata\local\programs\python\python39\lib\site-packages (from pandas) (2021.1)
Requirement already satisfied: numpy>=1.16.5 in c:\users\malth\appdata\local\programs\python\python39\lib\site-packages (from pandas) (1.20.1)
Requirement already satisfied: six>=1.5 in c:\users\malth\appdata\local\programs\python\python39\lib\site-packages (from python-dateutil>=2.7.3->pandas) (1.15.0)
I can even see the library in the site-packages folder.
Try creating virtual environment, configure it and then install whatever module you require. Its the most easiest way to skip module error anytime.
Try to do pip --version. If you have a multiple pythons on your pc, you might have a pip that linked to another version.
I guess you should try to use pyenv or virtualenv. This modules allowed you to avoid situation which I described above. Also it's a good practice to keep you python env isolated for a specific project.
As N.Singh has suggested, I would try to set up a new conda environment, adding all possible packages or libraries you will use and then I will make it active. Information about it can be found here: https://conda.io/projects/conda/en/latest/user-guide/tasks/manage-environments.html#activating-an-environment.
I really hope this helps. I have already had the same problem few months ago and worked for me.
Related
I have a Python tox project where I run the tox for running the test case and I came across one error a few hours back and am unable to resolve it till now. My module is using boto3 library and is installed using both the commands:
pip3 install boto3
pip install boto3 //for venv environments
When I try to install it again it gives me the below stack trace:
Requirement already satisfied: boto3 in ./venv/lib/python3.8/site-packages (1.26.34)
Requirement already satisfied: botocore<1.30.0,>=1.29.34 in ./venv/lib/python3.8/site-packages (from boto3) (1.29.34)
Requirement already satisfied: jmespath<2.0.0,>=0.7.1 in ./venv/lib/python3.8/site-packages (from boto3) (1.0.1)
Requirement already satisfied: s3transfer<0.7.0,>=0.6.0 in ./venv/lib/python3.8/site-packages (from boto3) (0.6.0)
Requirement already satisfied: urllib3<1.27,>=1.25.4 in ./venv/lib/python3.8/site-packages (from botocore<1.30.0,>=1.29.34->boto3) (1.26.13)
Requirement already satisfied: python-dateutil<3.0.0,>=2.1 in ./venv/lib/python3.8/site-packages (from botocore<1.30.0,>=1.29.34->boto3) (2.8.2)
Requirement already satisfied: six>=1.5 in ./venv/lib/python3.8/site-packages (from python-dateutil<3.0.0,>=2.1->botocore<1.30.0,>=1.29.34->boto3) (1.16.0)
But when I run tox it gives me the below error:
File "/Users/tony/IdeaProjects/abc/provisioner/.tox/py38/lib/python3.8/site-packages/api/lambda_handler.py", line 1, in <module>
import boto3
ModuleNotFoundError: No module named 'boto3'
Is there some path issue? I am using Python 3.8.10. I tried uninstalling and installing the packages but nothing changed.
Any help is much appreciated.
tox creates an isolated environment for building and testing. So, when you install a package somewhere, here boto3 with pip/pip3, maybe system-wide, tox ignores that - and that is a good thing, otherwise it would be impossible to have a clean test environment.
You need to provide the necessary dependencies to tox.
tox automatically installs a package, ie. when there is a setup.py or a pyproject.toml. You could also provide your dependencies directly via the deps configuration key:
[testenv]
commands = ...
deps = boto3
There is another way. You could "break" the test isolation by using the tox-current-env plugin, see https://pypi.org/project/tox-current-env/
Disclaimer
I am on of the tox maintainers.
import pandas
So I am working on a python project and want to import pandas library on https://replit.com/~
For some reasons, it shows some attribute error when I run the project.
Does anyone know ho do I fix or manually install pandas on replit?
Attaching Screenshot of an error herewith.
Usually packages have a lot of errors in replit but you can try this: -
Pandas does actually work on repl.it - you have to install it from the package manager. To do so, click the cube on the side navigation bar and type pandas into the search box. Then click on the pandas search entry and hit the plus sign. Tell me if this works!
Or
Broken package installs can usually be fixed by,
Updating pip and installing pandas from PyPI. By default, Repl.it comes with pip version 19.3.1, but the latest available version for python 3.8 is pip-21.1.1.
~/repl$ pip -V
pip 19.3.1 from /opt/virtualenvs/python3/lib/python3.8/site-packages/pip (python 3.8)
~/repl$ pip install pandas
Requirement already satisfied: numpy>=1.16.5 in /opt/virtualenvs/python3/lib/python3.8/site-packages (from pandas) (1.20.2)
Collecting pytz>=2017.3
Using cached https://files.pythonhosted.org/packages/70/94/784178ca5dd892a98f113cdd923372024dc04b8d40abe77ca76b5fb90ca6/pytz-2021.1-py2.py3-none-any.whl
Requirement already satisfied: python-dateutil>=2.7.3 in /opt/virtualenvs/python3/lib/python3.8/site-packages (from pandas) (2.8.1)
Requirement already satisfied: six>=1.5 in /opt/virtualenvs/python3/lib/python3.8/site-packages (from python-dateutil>=2.7.3->pandas) (1.15.0)
Installing collected packages: pytz, pandas
Successfully installed pandas-1.2.4 pytz-2021.1
Pandas does not work on replit at all, because a lot of modules, which Pandas needs to work properly, do not work in replit. An online Compiler is also not the best choice for doing dataprocessing, it would be better if you install an Interpreter for python on your PC.
I have a recurrent problem I have yet been unable to find an answer to.
Whenever I install a package in PyCharm through the terminal, whenever I try importing the module the package appears to not be installed. Or, like just now, the package may already be installed but when importing the module I get the error "No module named x":
C:\Users\TimStack\PycharmProjects\API>pip install requests
Requirement already satisfied: requests in c:\users\TimStack\appdata\local\programs\python\python37\lib\site-packages (2.23.0)
Requirement already satisfied: certifi>=2017.4.17 in c:\users\TimStack\appdata\local\programs\python\python37\lib\site-packages (from requests) (2019.11.28)
Requirement already satisfied: idna<3,>=2.5 in c:\users\TimStack\appdata\local\programs\python\python37\lib\site-packages (from requests) (2.9)
Requirement already satisfied: chardet<4,>=3.0.2 in c:\users\TimStack\appdata\local\programs\python\python37\lib\site-packages (from requests) (3.0.4)
Requirement already satisfied: urllib3!=1.25.0,!=1.25.1,<1.26,>=1.21.1 in c:\users\TimStack\appdata\local\programs\python\python37\lib\site-packages (from requests) (1.25.8)
Looking at these directories, it seems to refer to an old Python 3.7 installation. However, my environment uses 3.8.
What's the issue at hand here, and how do I go about solving it?
You need to uninstall the old 3.7 version as you have 2 conflicting Python versions.
OR
Specify your Python version when installing packages:
pip3.8 install [package name]
(3.8 for Python 3.8)
pip install takes --python-version <python_version> as argument.
You can pass 3.8 as argument and it will pick up the right one for you.
from the docs -
The Python interpreter version to use for wheel and "Requires-
Python" compatibility checks. Defaults to a version derived from
the running interpreter. The version can be specified using up
to three dot-separated integers (e.g. "3" for 3.0.0, "3.7" for
3.7.0, or "3.7.3"). A major-minor version can also be given as a
string without dots (e.g. "37" for 3.7.0).
I have Python2 and Python3 both installed in my laptop. I am trying to run pandas in Jupyter Notebook, but it shows an error message saying:
No module named 'pandas'
I have tried to install pandas in both python2 and python3 using:
pip3 install pandas
and
conda install pandas
both methods successfully installed the package but when I tried to import pandas, it shows the Error message again. I then tried:
!pip3 install pandas
but then it shows:
Requirement already satisfied: pandas in c:\users\fusuy\appdata\local\programs\python\python38-32\lib\site-packages (1.0.3)
Requirement already satisfied: pytz>=2017.2 in c:\users\appdata\local\programs\python\python38-32\lib\site-packages (from pandas) (2019.3)
Requirement already satisfied: python-dateutil>=2.6.1 in c:\users\appdata\local\programs\python\python38-32\lib\site-packages (from pandas) (2.8.1)
Requirement already satisfied: numpy>=1.13.3 in c:\users\appdata\local\programs\python\python38-32\lib\site-packages (from pandas) (1.18.1)
Requirement already satisfied: six>=1.5 in c:\users\appdata\local\programs\python\python38-32\lib\site-packages (from python-dateutil>=2.6.1->pandas) (1.14.0)
What should I do now?
Python is case sensitive. No module named 'Pandas' doesn't mean there is no module 'pandas'. Try: import pandas as pd. Besides that I wonder that conda install pandas was working, since your Python paths don't look like an Anaconda installation. However, if you're using conda, you first need to conda activate an environment before you can use it.
I had the same problem here.
I realize that I was trying to run the script without write python before the name script.
Beginners mistake... at least on my case
I'm new to python, coming from 6 months of c++ and am also new to VS Code (from VS).
My error is>
Exception has occurred: ModuleNotFoundError
No module named 'requests'
File "C:\Users\ryanb\Documents\Python\main.py", line 1, in
import requests
on anything which begins with :
import requests
this works fine in VS, but I have been encouraged to use Code. When I ran the pip command it said 'satisified'.
PS C:\Users\ryanb\Documents\Python> pip install requests
Requirement already satisfied: requests in c:\users\ryanb\anaconda3\lib\site-packages (2.22.0)
Requirement already satisfied: idna<2.9,>=2.5 in c:\users\ryanb\anaconda3\lib\site-packages (from requests) (2.8)
Requirement already satisfied: urllib3!=1.25.0,!=1.25.1,<1.26,>=1.21.1 in c:\users\ryanb\anaconda3\lib\site-packages (from requests) (1.25.8)
Requirement already satisfied: certifi>=2017.4.17 in c:\users\ryanb\anaconda3\lib\site-packages (from requests) (2019.11.28)
Requirement already satisfied: chardet<3.1.0,>=3.0.2 in c:\users\ryanb\anaconda3\lib\site-packages (from requests) (3.0.4)
PS C:\Users\ryanb\Documents\Python>
I have anaconda, though I'm new to it as well, but I seem to get the problem either way.
Initially my problem was that it wouldn't find the interpreter but this was resolved after I installed add on files to visual studio (not visual studio code) and used the interpreter which came with that.
Please advise.
Thank you
You may have several python versions installed (e.g. 3.6 32-bit, 3.6 64-bit, 2.7, ...). I would recommend to "natively" install Python from https://www.python.org/ instead of using Anaconda. The problem can happen because VS code is using another Python, different than the one you installed requests. You can verify this if pip3 is installed: try pip3 --version. Anyway, you can change the interpreter VS code is using by clicking the lower bar: screenshot
Or you might just run pip3 install requests.
I would recommend you to leave just one Python installed in your machine.