I am trying to write a python-script to work with dataframes imported from excel table and another one from another source. In order to read excel file into a pandas dataframe i selected "openpyxl" as a preferred engine, however PyCharm claims there is no such module - even though I have earlier installed it.
I am working on conda and i tried to install it both using pycharm terminal and my macbook terminal: when i retype "conda install openpyxl" it returns me
"# All requested packages already installed."
So please help me because it confuses me that PyCharm keeps screaming
"ImportError: Missing optional dependency 'openpyxl'. Use pip or conda to install openpyxl."
while terminal says i already have that module installed
This may happen because your pycharm is using a different interpreter than your command line.
To solve it:
In Pycharm, go to File, settings, project Interpreter, in the right top corner click the + button. Search for openpyxl and click Install package to install the latest version of the package.
Related
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
I have successfully installed npTDMS as seen here:
https://pypi.org/project/npTDMS/
If I try to install with command line using either pip or conda I get a message confirming it is already installed, and I see the package at D:\Users\username\anaconda3\pkgs.
On Spyder I have tried using the PYTHON path manager (in the tools menu) to add both:
D:\Users\username\anaconda3\pkgs\nptdms-1.2.0-pyhd8ed1ab_0
D:\Users\username\anaconda3\pkgs\nptdms-1.2.0-pyhd8ed1ab_0\site-packages\nptdms
As far as I understand this should be enough to use the npTDMS package, however when I try to import I get a ModuleNotFoundError: No module named 'nptdms'.
I'm fairly new to python overall so maybe there is a simple thing I am missing.
This issue comes when there are multiple versions of python or any package you are running at current time. The same issue was with me too when the IDLE was not able to detect the position of where the package is installed.
My suggestion is that uninstall all the versions of python and the module you are using and install them again. Otherwise shift to any other IDLE, in my recommendation - Visual Studio Code.
I am using Python 2.7 and am trying to run a program with openpyxl to work with xlsx files.
In the first line of code:
from openpyxl import Workbook
I get the following error when I run the program from the CMD:
ImportError: No module named openpyxl
I used pip to install version 2.6.0, and if I try to install it again through pip it just says I have the latest version.
Unlike any other question like this that I found here, I am using an IDE called PyCharm which has an option of running the program I am currently editing inside PyCharm, and PyCharm actually recognizes openpyxl and runs great, so why won't it work in the CMD?
This answer is for those who land in this page without having openpyxl installed.
run pip install openpyxl command in your terminal
If you have multiple versions of python installed it might be related to the version of python that's added to your system path.
What I would suggest you do is check your system path and verify that indeed the python/pip you are using from the command line is 2.7. The same thing applies for PyCharm.
If you need help inspecting your system variables on windows: Check this link out!
I downloaded and installed the latest Python (3.7), and installed pyodbc both through the standard "pip install pyodbc" method and downloading and installing the unofficial wrapper. But still, in my script that uses pyodbc, PyCharm underlines pyodbc in red, and when I hover my mouse over it, it tells me "module not found". On my Settings | Project Interpreter screen, it shows that pyodbc is installed, and when I run my script, it works.
My problem is that it doesn't show me function arguments when I type a function name and the open parenthesis, as it does for modules that it knows about. I would like to get rid of the error marker and get the benefits of PyCharm's full support for pyodbc. How do I do that?
Note: This is very close to a duplicate of a question I posted over a year and a half ago, but I did not get an answer that helped at that time. One commenter on that thread suggested I uninstall pyodbc and then run python -m install pyodbc. I did that, and got no change.
UPDATE: The following answer was based on testing with PyCharm 2018.1. PyCharm 2018.2.1 includes an updated "packaging_tool.py" that plays nicely with pip 10+.
TL;DR: Update your PyCharm.
I was able to reproduce your issue with pip 18.0. When PyCharm installs a package from File > Settings > Project Interpreter it calls a helper script named "packaging_tool.py" which is incompatible with pip versions 10 and higher, so attempting to install any packages from there will result in
AttributeError: module 'pip' has no attribute 'main'
JetBrains will have to fix that script to completely resolve the issue. (Their current workaround appears to be to pin pip at version 9.x. Even though Project Interpreter window lists pip 18.0 as "latest" it won't upgrade to it if we select pip and click the upgrade (up arrow) button.)
In the meantime, a workaround for pip_10+ is to
open a Terminal window in PyCharm (AltF12),
run pip install pyodbc,
close the Terminal window and open File > Settings > Project Interpreter,
try to install some other package, like pandas (the install will fail for the same reason),
close the "Available Packages" dialog, then
click the "OK" button to close the "Settings" dialog.
That should trigger PyCharm to re-scan the installed packages and enable pyodbc code completion in the PyCharm editor. (You may need to restart PyCharm for the change to take effect.)
So, I've installed xlsxwriter via pip just fine -- scripts run no problem. My issue is that I can't find where the actual files are installed to (because PyCharm IDE doesn't detect that xlsxwriter is actually installed and has that annoying red underline)
So, as you can see in the attached picture, when I run pip uninstall xlsxwriter it is showing that it's installed in \lib\site-packages\xlsxwriter\
but that folder simply does not exist as far as I can tell, not even as a hidden directory.
In the end, I really just want PyCharm to stop underlining modules that are installed, but this appears to be the case with a few different modules and I just want to get to the bottom of it.