How can I solve the "ModuleNotFoundError: No module named 'psycopg2" problem? - python

I have a problem with VS Code. I think the problem ir related to the environment of the code.
Im trying to import the psycopg2 pool method (from psycopg2 import pool) after installing it with pip install psycopg2, and it says that ModuleNotFoundError: No module named 'psycopg2'
How can I fix it?

Press Ctrl+shift+p, type Python: Select Interpreter and choose the correct environment if it is an environment issue.

The packages installed in the python environment you have selected can work.
You can through pip show psycopg2 to know where have you installed the psycopg2.To know which python interpreter you have selected from the bottom-left on the VSCode.
And after you switch the python interpreter, remember to renew a terminal(shortcut Ctrl+Shift+`), the python extension will activate this python environment in the terminal, then the packages can be installed in the right place.

Related

Installed selenium with pip, folder is in site-packages, using correct interpreter, but still cannot import (Win10, Python 3.10.9)

I'm trying to use selenium, but can't get python to recognize it.
I installed it first using "pip install selenium" and "pip install webdriver-manager". It is in the folder "C:\Users\{username}\AppData\Local\Programs\Python\Python310\Lib\site-packages\selenium", but I get the error "ModuleNotFoundError: No module named 'selenium'" when I try to import it.(https://i.stack.imgur.com/dVplU.png)
(https://i.stack.imgur.com/wiREJ.png)
Here it is shown as installed with the command "pip list"
(https://i.stack.imgur.com/QhOu7.png)
I also tried uninstalling it and reinstalling with flags that I saw some people say worked, but it didn't make a difference.
(https://i.stack.imgur.com/VTTMU.png)
I only have one python interpreter version installed, 3.10 (so only one python folder, "Python310"). I have pandas in the same site-packages folder which I can import and use no problem.
If anyone knows what the issue might be, please let me know. I can't figure it out for the life of me.
Okay, I solved the issue by completely uninstalling the interpreter which I got from the Microsoft Store and reinstalling it from the official Python website. Now "from selenium import webdriver" works.
Somehow selenium installed in the global scope is not getting recognized within the Virtual Environment of VS Code / PyCharm.
Solution
You need to install Selenium within the Virtual Environment.
Within the Terminal execute the command:
pip install -U selenium

how to clear unresolved import 'cv2' error?

I have installed Python 3.9 on my ubuntu 18.04 desktop, i have already installed two libraries using pip3 install
1)opencv-contrib-python
2)opencv-python
Currently i am writing a program in VSCode for which i am importing cv2
I have already default version of python 3.6.9 in my computer. When i use default version as interpreter, program seems to be working fine.But if i switch the interpreter to newly installed python 3.9 , i get an error
ModuleNotFoundError: No module named 'cv2'
please someone who has faced such problem and know how to resolve it help me!!!...
The reason is as you described: it is due to the use of the Python environment.
The module "cv2" is installed in "lib\site-packages\" in python3.6.9, but when we use "python3.9" without the module "cv2" installed, VS Code is in "python3.9" The module could not be found in "lib\site-packages\".
You could use the command "pip3 --version" to check the source of the module installation tool, the module is installed in "lib\site-packages\" here:
When using the command "pip3 show opencv-python" to check its installation location: (...\python\python38\lib\site-packages)
Therefore, if you want to use the module "cv2" in "python3.9", please install it in this environment. In addition, it is recommended that you use a virtual environment, it will be stored in "lib\site-packages" in the folder of the project so that you could check it more intuitively.

Pip install works in terminal but packages arent there in Pycharm?

Ok, I'm trying to install various packages like pandas and NumPy in Pycharm, and via Terminal (I'm on a mac), they are installed without issues and I can list them with pip list -
Then, however, when I go to Pycharm and do an import, I get the error
ModuleNotFoundError: No module named 'pandas'
I tried the Pycharm settings and installing the package there, but then I get-
What is wrong here?
Interpreter:
You are probably using the wrong interpreter within pycharm when executing the code with the import statement. Check settings > project > project interpreter and make sure that the correct interpreter is selected.

PyCharm throws Error "No module named pymongo"

I'm new to Python and just want to connect to MongoDB.
When trying to install pymongo, cmd tells me that the "requirement is already satisfied".
When trying to import pymongo in Pycharm, however, the ModuleNotFoundError is thrown.
I've reinstalled PyCharm with no change.
Any ideas how to fix this?
Settings => Project: => Project Interpreter
look for packages and install pymongo package
https://www.jetbrains.com/help/pycharm/installing-uninstalling-and-upgrading-packages.html
You may have more than one version of python installed in your device and install library in one of them. Type in cmd "where python" and you can see all versions. If you have some version, you need to configure a desire Python interpreter in pycharm.

importError: no module named _winreg python3

Where can I download _winreg for python3 if I can at all. I have my 'windir' on E:\Windows. I do not know if cx_Freeze did not notice that. I am using cx_Freeze to create an msi installer.
As it says in the _winreg documentation, it has been renamed to winreg in Python 3.0. You should run the 2to3 tool if you're converting code that was written for Python 2.x.
I know this is an old question, but this was the first search result when Googling for ModuleNotFoundError: No module named '_winreg', and perhaps may be helpful for someone.
I got the same error when trying to use a virtual environment folder, which has been created using different (already deleted) python binaries. The solution was recreate the virtual environment:
Delete the virtual environment folder
Run python -m venv <name_of_virtual_environment>
I have found an easy solution for this, Even though i found it after a lot of Rnd, the solution implementation is so simple and straight forward. Hope it can help many people with the same problem.
If you dont have the latest version of Python installed on your machine, You need to download it from (https://www.python.org/downloads/) and then click on Add to path option and just finish the installer.
Please open CMD and move to the python latest version directory, then run the pip install package name (e.g) pip install pygame and it will be successful
1. C:\WINDOWS\system32>cd C:\Users\admin\AppData\Local\Programs\Python\Python37-32
2. C:\Users\admin\AppData\Local\Programs\Python\Python37-32>pip install Pygame
It will install the packages now without any issues.
Downloading
Successfully installed Pygame-1.9.4
C:\Users\admin\AppData\Local\Programs\Python\Python37-32>
If you are still facing issues in Pycharm after trying the above solution, please try the following steps too.
Create new virtual Environment from settings menu and select the latest version of python framework as Project Interpreter and give a new folder path.
select the pip package you want to import. Recompile the code and the error will clear.
Hope this helps.
When you encounter an error like module of simpleai not found,
use
pip install simpleai
in the prompt and then execute. It will get installed.

Categories

Resources