0

I am using Python 3.6.4 , and pip 18.0. I have successfully installed numpy and pywin32 with pip, however when I try to import them in a file using notepad like so:

import numpy
import win32com.client

I get these errors when running the file:

Traceback (most recent call last):
  File "C:\Users\Joshua\Desktop\Python\test.py", line 1, in <module>
    import pandas
  File "C:\Program Files\Python36\Lib\site-packages\pandas\__init__.py", line 19, in <module>
    "Missing required dependencies {0}".format(missing_dependencies))
ImportError: Missing required dependencies ['numpy']

Or

Traceback (most recent call last):
  File "C:\Users\Joshua\Desktop\Python\test.py", line 1, in <module>
    import win32com.client
  File "C:\Program Files\Python36\Lib\site-packages\win32com\__init__.py", line 5, in <module>
    import win32api, sys, os
ImportError: No module named win32api

However the confusing and frustrating thing is if I try to import these modules directly in the python interpreter like:

python.exe
>>> import numpy
>>> import win32com.client

There is no error and I can use all of the classes and functions of these modules.

All of these modules are located in the site-packages directory which is referenced in my Path and PYTHONPATH environment variables:

PYTHONPATH=C:\Program Files\Python36\Scripts;C:\Program Files\Python36;C:\Program Files\Python36\Lib\site-packages;
Path=C:\Program Files\Python36\Scripts;C:\Program Files\Python36;C:\Program Files\Python36\Lib\site-packages

And I can confirm that the site-packages directory is listed in the sys.path property:

>>> import sys
>>> print("\n".join(sys.path))

C:\Program Files\Python36\Scripts
C:\Program Files\Python36
C:\Program Files\Python36\Lib\site-packages
C:\Users\Joshua\Desktop\Python
C:\Program Files\Python36\python36.zip
C:\Program Files\Python36\DLLs
C:\Program Files\Python36\lib
C:\Program Files\Python36\lib\site-packages\win32
C:\Program Files\Python36\lib\site-packages\win32\lib
C:\Program Files\Python36\lib\site-packages\Pythonwin
>>>

I am at a loss for what is wrong...

Joshua Yonathan
  • 490
  • 1
  • 5
  • 16
  • 1
    Add a `print(sys.version_info)` line to the `.py` script file created in notepad and make sure it's using the same `python.exe` that's run when you invoke the interpreter directly. If not, then the wrong version is associated with the `.py` file extension in the Windows registry. You also need to `print("\n".join(sys.path))` in the script file to see if it's correct. – martineau Sep 29 '18 at 19:39
  • @martineau well how about that. It is using python 2.7.14 even though that version is no where to be found in the system path. Do you know how to fix this? – Joshua Yonathan Sep 29 '18 at 23:56
  • @martineau oddly enough, I changed the name of the version 2 python.exe file to python2.exe, ran the .py file and it worked, but then when I changed the name of python2.exe back to python.exe and ran the .py file again, it still worked. So everything seems to be fine now, but I still would like to know why that happened... – Joshua Yonathan Sep 30 '18 at 00:28
  • Joshua: It's possible to manually control the file-type to application mapping that Windows does. Most installers do it automatically or ask if you want it to be done. Here's an older [answer](https://stackoverflow.com/a/5586761/355230) of mine that describes how to do it. – martineau Sep 30 '18 at 02:27

0 Answers0