Python Forum
Problem with importing an installed package
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Problem with importing an installed package
#1
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)?
Reply
#2
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.
Reply
#3
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.
Reply
#4
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.
Reply
#5
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.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  problem install somewhere package akbarza 1 430 Dec-27-2023, 01:25 PM
Last Post: Gribouillis
  imdby package problem lunacy90 8 1,035 Sep-04-2023, 07:13 PM
Last Post: deanhystad
  when package built, requirements not installed sabuzaki 1 703 Apr-07-2023, 09:01 AM
Last Post: sabuzaki
  Problem with importing python-telegram library into the project gandonio 1 1,516 Nov-01-2022, 02:19 AM
Last Post: deanhystad
  Problem with importing Python file in Visual Studio Code DXav 7 4,911 Jun-15-2022, 12:54 PM
Last Post: snippsat
  Problem: Restart kernel onPydev console when trying to install a python package poppy2020 1 7,567 Nov-25-2020, 06:13 PM
Last Post: Larz60+
  pip list to show all versions of a package installed pvbadiger05b 4 2,430 May-21-2020, 06:48 PM
Last Post: jameshonest
  Package installed through Anaconda "not found" by Python zonova 0 2,256 May-08-2020, 11:50 PM
Last Post: zonova
  Importing module from a package results in import error goghvv 2 2,341 Mar-27-2020, 07:13 PM
Last Post: goghvv
  Error importing package julio2000 3 3,709 Jan-26-2020, 06:15 PM
Last Post: buran

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020