Python - Package installed into site-packages but won't import - python

I have installed the package xlrd but am unable to import it when using my IDE (Rodeo).
Having looked at a few questions on stackoverflow, I still can't work out why I get the following error:
ImportError: No module named 'xlrd'
The xlrd folder in site-packages does have an __init__.py file.
Additionally, if I attempt to import xlrd using the Command Prompt, I get no errors. But I do when using Rodeo.
While trying to solve this problem, I have added the file location of site-packages (C:\Users\HP\AppData\Local\Programs\Python\Python36-32\Lib\site-packages) to the System Variables "Path", although I'm not sure what this does or if it's relevant.
I am using Python 3.6 and am a Python beginner so would appreciate any answers to be described in a basic way!

Related

Python 3 How to resolve No module named '_win32com' error?

I'm using Python 3 and working in Pycharm.
I was able to get pywin32 and win32com working on one project, but since I have tried importing them into a new project, they don't seem to be working. At first I was getting No module named 'win32api', but I updated the win32com\__init__.py from import win32api to from win32 import win32api. That seems to have fixed the initial error, but now I'm getting No module named '_win32com'. This seems to be from issues with \pythoncom\__init__.py maybe?
I've tried uninstalling and reinstalling pywin32 and pypiwin32 as well.
Example of code here:
import win32com.client as win32
xlapp = win32.DispatchEx("Excel.Application")
wbe = xlapp.workbooks.open(r"C:\Users\me\example.xlsx")
I decided to try again with a new project and install the packages globally and that has fixed the issue. Still not sure why it wasn't working when installing locally, but using global installs seems to be good solution.

'reportMissingModuleSource' and 'reportMissingImports' errors for imported modules pandas and alpha_vantage

I'm very new to python and trying one of my first projects. I have installed modules 'pandas' and 'alpha_vantage' and imported them at the top of my code but they show the errors 'reportMissingModuleSource' for pandas and 'reportMissingImports' for alpha_vantage. I installed them in Command prompt and it was successful but it seems python doesn't recognise them or cant find them.
Potentially useful info:
When I first installed python I had to go into my Path settings and create a new Path to python.
I use VSCode
I had issues installing pip I cant remember why because I've been at this for hours.
Python version is 3.10.5 64bit
Pip version is 22.1.2
I am on Windows
I don't know what python files need to go where so they are slightly scattered around my directory.
Do I need to create a Path in my settings to each module, I already have one going to my scripts folder. I am very stuck so any help is appreciated.
Thank you for anyone that helps!

"ModuleNotFoundError: No module named '...' even though module is installed

Trying to import "libgen_api" module but get "Module not found" error.
Pip install libgen-api shows "requirement already satisfied" and the module exists in the python folder as well.
The documentation of the module says that it has to be called with libgen_api.
Other modules work fine. I am using VScode but the problem persists in the python terminal as well. I apologize if this question is redundant but so far I have not been able to find a solution anywhere.
The problem was that VScode sys.path showed python38-32 but the module was installed in python39. To fix the issue go to View -> Command pallete -> select interpreter and make sure to use the version under which pip installed the module.
This answered my question.
How can I change python version in Visual Studio Code?

Python imports suddenly failing

I had a few imports I was using for my project. Some of these included packages I downloaded using pip like
import MySQLdb
While others were modules from within my project like
sys.path.append(os.path.join(os.path.dirname(__file__), "../")) .
from util.myFile import get_mysql_connection, execute_query,
These were all working and I was able to run my application on PyCharm. I closed PyCharm and opened it back up to find most of these imports "could not be found". Any help regarding this will be much appreciated. Thanks
Update:
I'm able to run the file from terminal (iTerm) without errors. However, the file still shows red error marks by the imports. Seems like PyCharm isn't recognizing some sort of path
Check the traceback for what version of python is being called.
There could be a mismatch between the version you've imported modules with and the version that runs by default.
Double check what is being used as your project interpreter. This can change the available packages to your current project.
Found in PyCharm by going to Settings -> Project:<'Your-Project'> -> Project Interpreter
Also, did you install MySQLdb in this way? MySQLdb - ModuleNotFoundError

Python refuses to recognize library I am almost certain exists

I have no idea why this is so frustrating, but I have literally pulled out a few clumps of hair in rage because this just refuses to work and I honestly do not have the slighest clue on what to do. I am trying to use the winshell module for a quick python programming I am using. I am new to python and just started trying it today. I have tried to install the library manually, and through pip. pip claims the module is downloaded, and I can see it in the lib folder. No matter what I do I get this error when I try to run my code:
import winshell
ModuleNotFoundError: No module named 'winshell'
what on earth must I do to get this to work I am at my wits end here and I feel like I'm going to break something
You have to install the library with:
pip install winshell
I just tested with pip3 install winshell and it worked.
Python interpreter search for modules in the set of directories that you can see with:
import sys
print(sys.path)
I recommend you take a look to see if the directory where you are seeing the library in lib is include in that list.
Might be useful to you read: The Module Search Path

Categories

Resources