Python Forum
Problem with importing an installed package - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: Problem with importing an installed package (/thread-18997.html)



Problem with importing an installed package - Reverend_Jim - Jun-09-2019

I installed pymsgbox using pip. I created a sample file that does only

import pymsgbox
pymsgbox.alert("some text")
When I run it from the command line (like most of my scripts) by typing "sample" I just get "ModuleNotFoundError: No module named 'pymsgbox'". When I run it by typing "python sample.py", or when I run it through IDLE, or when I run python.exe and type the code in manually, everything runs just fine. Can someone suggest how to fix this (I suspect a config problem of some sort)?


RE: Problem with importing an installed package - SheeppOSU - Jun-09-2019

When typing the python before hand, it runs with python and the module is found. Without python, it tries to just run it and it doesn't work.


RE: Problem with importing an installed package - Reverend_Jim - Jun-09-2019

I don't understand what you are saying. When I run other python scripts from a cmd shell via Windows file association they work fine. The one that imports pymsgbox does not.

Got a solution. When I ran ftype I got

D:\Utils>ftype | grep -i python
Python.ArchiveFile="C:\WINDOWS\py.exe" "%L" %*
Python.CompiledFile="C:\WINDOWS\py.exe" "%L" %*
Python.File="C:\Program Files\Python36\python.exe" "%L" %*
Python.NoConArchiveFile="C:\WINDOWS\pyw.exe" "%L" %*
Python.NoConFile="C:\WINDOWS\pyw.exe" "%L" %*

I reset Python.File to C:\Program Files\Python36\python.exe and now things work as they should. I'll be resetting the rest shortly.


RE: Problem with importing an installed package - SheeppOSU - Jun-10-2019

Did the other python scripts you ran have imports

Let me try and elaborate more. When windows runs it, it gets this import that it cannot find because it just looks in the same directory. When it is run with Python (python sample.py), Python knows to also look in another folder located somewhere on the computer holding the imports.

I don't really understand your problem here tho. Were you just asking about it? Wanted to fix it? The only way to fix this is to just use python to run the file as in "python sample.py" in the cmd, or run it as an .exe, or just run it from the IDLE or IDE.


RE: Problem with importing an installed package - Reverend_Jim - Jun-14-2019

I don't see how I could be any clearer. Until I did the mod to Python.File my example wouldn't work when run as

D:\>pymsgtest

but it would work when I did

D:\>python

and then typed the two lines in. I presume the problem is related to the py.exe and pyw.exe in C:\Windows plus the fact that there are several copies of python on my computer, only one of which I actually intentionally installed. The others were installed along with Visual Studio, Open Office and JASC PaintShopPro. There is either a conflict between the versions or a config problem. Using Windows settings and looking at app defaults by file type, Windows just reports "Python" for both py and pyw extensions without showing which Python it is defaulting to. Thanks Microsoft.