I have been working with a package called openpyxl which I installed last week.
My system is windows 10
This morning, all code with "import openpyxl" fails with the error
ModuleNotFoundError: No module named 'openpyxl'
So after I calm down, I decide I have to reinstall openpyxl.
I find the pip3.7.exe in the C:\Users\Owner\PycharmProjects\venv\Scripts
and try to reinstall openpyxl
the PIP runs fine (I think) that I already have it
"Requirement already satisfied: et_xlmfile in c:\users\owner\pycharmprojects\venv\lib\site-packages (from openpyxl)
Yet when I go back to my development environment (pycharm) the same issue exits:
ModuleNotFoundError: No module named 'openpyxl'
any clues as to how I can overcome this and can once again do an include opnpyxl ???
venv
usually mean that's it's a virtual environment.
Then virtual environment need to be active or you need to use
python.exe
in
venv/Scripts
folder,
to use what pip installed to environment.
You should learn how
venv work without including any editors.
Here a run i use
cmd
don't like want to always use
cmder,
but use
cmd
to show exactly how it work there.
Microsoft Windows [Version 10.0.17134.407]
(c) 2018 Microsoft Corporation. Med enerett.
C:\Windows\System32>cd\
C:\>cd code
# Make environment
C:\code>python -m venv my_env
# Cd in
C:\code>cd my_env
# Activate
C:\code\my_env>C:\code\my_env\Scripts\Activate
# Check pip
(my_env) C:\code\my_env>pip -V
pip 10.0.1 from c:\code\my_env\lib\site-packages\pip (python 3.7)
# Install openpyxl
(my_env) C:\code\my_env>pip install openpyxl
Collecting openpyxl
Downloading https://files.pythonhosted.org/packages/38/7f/.....
100% |████████████████████████████████| 174kB 1.8MB/s
Installing collected packages: jdcal, et-xmlfile, openpyxl
Running setup.py install for et-xmlfile ... done
Running setup.py install for openpyxl ... done
Successfully installed et-xmlfile-1.0.1 jdcal-1.4 openpyxl-2.5.11
# Check that it work
(my_env) C:\code\my_env>python
Python 3.7.1 (v3.7.1:260ec2c36a, Oct 20 2018, 14:05:16) [MSC v.1915 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> from openpyxl import Workbook
>>> wb = Workbook()
>>> exit()
(my_env)
When environment is deactivate,most use
python.exe
in folder
C:\code\my_env\Script
folder.
Editors like PyCharm and VS Code can detect virtual environments,look at doc for more on this.
Thank you very much for the well thought out and clear message.
It is true that you have to have the python.exe in the same location as the code (script)?
I have python installed elsewhere and if I just move the .exe I am afraid it will break everything it depends on. In your reply, it was assumed they were in the same place.
If they have to be in the same place, that means I have to reinstall Python for every project I work on. I will have dozens of them around and I could not keep them all updated.
So would you be so kind as the resend your clear instructions with the following change?
Python resides in c:\windows The working environment where the code resides is the directory C:\Users\Owner\PycharmProjects
there are subdirectories for each project. The current project subdirectory is:
C:\Users\Owner\PycharmProjects\PyGA
Must I reinstall Python in C:\Users\Owner\PycharmProjects\PyGA ?
Thank you for taking the time to reply. It was great of you to do that.
(Nov-26-2018, 04:21 PM)wardogelwood Wrote: [ -> ]It is true that you have to have the python.exe in the same location as the code (script)?
I have python installed elsewhere and if I just move the .exe I am afraid it will break everything it depends on.
No you shall never move any .exe at all.
You most understand the difference between virtual environment,and the Python you have installed in OS.
The main purpose of Python virtual environments is to create an isolated environment for Python projects.
So it's like new python installation that has nothing to do with Python version installed on OS.
(Nov-26-2018, 04:21 PM)wardogelwood Wrote: [ -> ]Python resides in c:\windows The working environment where the code resides is the directory C:\Users\Owner\PycharmProjects
Look at this for OS installation
Python 3.6/3.7 and pip installation under Windows
So i OS Python version placed in
C:\python37
.
So
python
and
pip
command will work from an in anywhere in cmd.
C:\>python -V
Python 3.7.1
C:\>pip -V
pip 18.1 from c:\python37\lib\site-packages\pip (python 3.7)
When a make virtual environment in previous post,it like a new installation that live on is own.
When virtual environment is
Active
(my_env) it will always use
python.exe
in
my_env/Scripts
folder no matter where .py file is placed.
Deactivate then will
python.exe
(OS) take over or have to use(dc in) python.exe in my_env\Scripts.
Learn how basic setup work without using PyChram,then take a look at
Configuring Python Interpreter PyCharm.
Thank you for your help. I have solved my problem (for now anyway).
Since I have Python installed in two separate places I also have 2 different versions on pip installed.
I was updating the library of the Python that was not the one being used by PyCharm.
So I went to the directory where PyCharm's Python was located and ran the pip install there.
Now everything is cool again, and I can make progress.
However, why it was working for days before and suddenly stopped is still a mystery. I must have had a temporary path variable set somewhere.
Thanks for your help. I do take your teachings on virtual environments to heart, but I have bigger fish to fry just now.