Cannot import an installed module - python

I cannot import a module which is installed
ModuleNotFoundError: No module named 'Google'
It is installed as when I run
pip install Google
I get:
Requirement already satisfied: soupsieve>1.2 in /Users/sebastianstros/Library/Caches/pypoetry/virtualenvs/mama-bots-9Qh4WGwv-py3.9/lib/python3.9/site-packages (from beautifulsoup4->Google) (2.3.2.post1)
But importing the module I get:
Traceback (most recent call last):
File "/Users/sebastianstros/PycharmProjects/mama-bots/mama_bots/bots/calendar_bot/personal_calendar_bot.py", line 7, in <module>
from Google import Create_Service
ModuleNotFoundError: No module named 'Google'
Even though this evaluates to True:
print(sys.path[-1] == "/Users/sebastianstros/Library/Caches/pypoetry/virtualenvs/mama-bots-9Qh4WGwv-py3.9/lib/python3.9/site-packages")
Which is surprising to me as sys.path is a list of paths from which modules can be taken and the right hand side of the statement is the location of the module.

Because there is actually no package called Google, you may try pip install google for the Google libraries.
You can check all the packages from PyPI website.

Related

Tensorflow - ModuleNotFoundError: No module named 'reverb'

When i run a python program, it shows the error message
sam#MSI:~/circuit-training$ python3 -m circuit_training.learning.ppo_reverb_server --root_dir=${ROOT_DIR} --port=${REVERB_PORT}
Traceback (most recent call last):
from circuit_training.learning import ppo_reverb_server_lib
File "/home/sam/circuit-training/circuit_training/learning/ppo_reverb_server_lib.py", line 20, in
import reverb
ModuleNotFoundError: No module named 'reverb'
To solve it, I install the packages by using pip install reverb, and it shows
Defaulting to user installation because normal site-packages is not writeable
Requirement already satisfied: reverb in /home/sam/.local/lib/python3.8/site-packages (2.0.1)
It seems like i already have this package, but when i import reverb, it still saying that ModuleNotFoundError: No module named 'reverb'
Is it because import cannot find the package path?

Can't immediately import a module installed on script when using the pip --prefix option

import subprocess
import sys
sys.path.append("/home/user/python_install/lib/python3.6/site-packages")
try:
from pytz import reference
except:
subprocess.call([sys.executable, "-m", "pip", "install", 'pytz', "--prefix=python_install"])
from pytz import reference
In the above code snippet, if initial import fails I want to install the module in a local folder and retry the import.
The issue that I'm facing is that the import (after installation) is not working in the 1st run of the script:
Installing collected packages: pytz
Successfully installed pytz-2021.1
Traceback (most recent call last):
File "timezone_test2.py", line 17, in <module>
from pytz import reference
ModuleNotFoundError: No module named 'pytz'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "timezone_test2.py", line 20, in <module>
from pytz import reference
ModuleNotFoundError: No module named 'pytz'
On the next runs of the script the module is imported without any issue.
Already validated that sys.path is correct, and pip installs the module in the right place.
If I remove "--prefix=python_install" to use instead the default directory, the same strategy works at 1st (even if module is not installed).
Also if I try pip3 install --prefix="/home/user/python_install" pytz and then run the script, it is capable of import the module at first run without issues.

ModuleNotFoundError: No module named 'cx_Oracle' in Visual Studio Code

I would like to connect to Oracle database from VS Code. In the Terminal I ran
pip install cx_oracle
and it stated:
Requirement already satisfied: cx_oracle in c:\python38\lib\site-packages (8.1.0)
but when I ran the code: import cx_Oracle it returned:
---------------------------------------------------------------------------
ModuleNotFoundError Traceback (most recent call last)
<ipython-input-8-1e79d9171cfb> in <module>
----> 6 import cx_Oracle
ModuleNotFoundError: No module named 'cx_Oracle'
In Extensions in VS Code I entered cx_Oracle in the search bar and it showed No extensions found.
How to use 'cx_Oracle' in VS Code?
Update:
Changed the interpreter to python38 as seen in screenshot below but didn't seem to work.
Try to download the whl file of cx-Oracle from here.
For example download the file to F:/file.
Then use command pip install F:/file/cx_Oracle-8.1.0-cp38-cp38-win_amd64.whl to install.

Failing to install Python openpyxl module

I have installed the openpyxl Python module in my machine, or at least I thought I've done that. I entered these commands on the command prompt (on Windows):
C:\Users\gluti>cd C:\Users\gluti\PycharmProjects\Data Structures\venv\Scripts
C:\Users\gluti\PycharmProjects\Data Structures\venv\Scripts>pip install openpyxl==2.1.4
And then, it shows a message, saying that the module openpyxl was successfully installed. However, when I try to import this module on Python IDLE, it shows the following error message:
import openpyxl
Traceback (most recent call last):
File "<pyshell#0>", line 1, in <module>
import openpyxl
ModuleNotFoundError: No module named 'openpyxl'
Did I miss something or am I installing the module in the wrong directory?
It is possible you have installed python 2 and python 3 so there are two different versions of pip on your machine.
You need to ensure you are installing openpyxl in the same type of python that you are using to run the script.

no module named pycountry

Attempting to import and use pycountry in python 2.7.
import pycountry
len(pycountry.countries)
However, module is not recognised.
Traceback (most recent call last):
File "countries_list.py", line 1, in <module>
import pycountry
ImportError: No module named pycountry
You have to install it using pip.
pip install pycountry
And then you can use it :)
I had the same problem and looked thru several articles and youtube videos but none got my pycharm fixed to recognize the pycountry module until I tried executing the program in the pycharm IDE terminal and then the pycharm EDE started to recognize it.

Categories