Reputation: 2357
I've just installed Python for the first time and I'm trying to reference the win32com module however, whenever I try to import it I get the message "no module name win32com".
Any ideas?
Upvotes: 12
Views: 47087
Reputation: 151
the below plus add pywin32 in PyCharm setting work for me
python -m pip install pywin32
Upvotes: 15
Reputation: 60577
Since win32com is a Windows-specific package, this answer will be geared towards Windows users.
You can use a package manager like pipenv to manage your dependencies.
pip install pipenv
).pipenv install pypiwin32
to install the package.pipenv run main.py
Example main.py
code:
import win32com
print(win32com)
If pipenv isn't your thing, you can use the built-in virtual environments.
python -m venv venv
to setup you virtual environment.venv\Scripts\activate.bat
from your project directory whenever you want to use this virtual environment (you will see (venv)
added to your shell prompt to know it's activated).pip install pypiwin32
from your active virtual environment to install the package.python main.py
so long as the virtual environment is active.This is not typically recommended, but included anyway.
pip install pypiwin32
you can install the package globally.python main.py
.Upvotes: 6
Reputation: 71
When working with python projects its always a good idea to create a so called virtual environment, this way your modules will be more organized and reduces the import errors.
for example lets assume that you have a script.py which imports multiple modules including pypiwin32.
sudo apt install virtualenv
.virtualenv venv
it creates a folder named venv
in that directory.source /path/to/venv/bin/activate
if your already in the directory where venv exists just issue source venv/bin/activate
pip install pypiwin32
or pip install pywin
Upvotes: 2
Reputation: 71610
You should try using pip
this way:
pip install pypiwin32
It is pypiwin32
which should work.
Upvotes: 1
Reputation: 81684
As it is not built into Python, you will need to install it.
pip install pywin
Upvotes: 9