'No module named win32com
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?
Solution 1:[1]
Since win32com is a Windows-specific package, this answer will be geared towards Windows users.
Option 1: Install locally with pipenv (recommended)
You can use a package manager like pipenv to manage your dependencies.
- Ensure you have pipenv installed (
pip install pipenv). - In your project directory, run
pipenv install pypiwin32to install the package. - Now you can run your code using commands like the following
pipenv run main.py
Example main.py code:
import win32com
print(win32com)
Option 2: Install locally with venv (recommended)
If pipenv isn't your thing, you can use the built-in virtual environments.
- From your project directory, run
python -m venv venvto setup you virtual environment. - Run
venv\Scripts\activate.batfrom 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). - Run
pip install pypiwin32from your active virtual environment to install the package. - You can run your code like
python main.pyso long as the virtual environment is active.
Option 3: Install globally (typically not recommended)
This is not typically recommended, but included anyway.
- Using
pip install pypiwin32you can install the package globally. - Then you can run your code with just
python main.py.
Solution 2:[2]
the below plus add pywin32 in PyCharm setting work for me
python -m pip install pywin32
Solution 3:[3]
This will work as well
python -m pip install pywin32
Solution 4:[4]
You should try using pip this way:
pip install pypiwin32
It is pypiwin32 which should work.
Solution 5:[5]
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.
here are the steps to solve your problem:
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/activatepip install pypiwin32 or pip install pywinSources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Alexander O'Mara |
| Solution 2 | Yibingqing Jiang |
| Solution 3 | Rahul Kumeriya |
| Solution 4 | U12-Forward |
| Solution 5 | arez |
