My main script is in (local-directory)/desktop/code and I'm trying to import a Python script from the same folder by running:
import gui.pyw
The GUI loads when I execute the main script but the main script doesn't.
When I close the GUI, it gives me the error:
ModuleNotFoundError: No module named 'gui.pyw'; 'gui' is not a package
I don't know why it's not finding it. any help is appreciated :)
Maybe be you should just write import gui. When you are writing import gui.pyw, it is assuming pyw as a function in the gui script instead of importing/running the whole script.
Related
I am trying to run a python script and I wanted d to run it with a more pythonic way rather than maybe calling subprocess.run().
I found the runpy library and I am trying to call my script like this:
runpy.run_path(path_name='/home/dir1/dr2/dr3/run_code.py', run_name='__main__')
This returns me and error that one of the modules used in the run_code.py does not exist:
ModuleNotFoundError: No module named 'fluent_logger'
When I run the same script with subprocess.run() I get no errors.
Am I using this the wrong way?
I work on python and I want to import a module just after execute a command with python in the same script. I need to execute the command before importing the module.
When I start to execute my command on a console, then I can open python and import MyModule but if I pass my command by python then import MyModule report in console :
ImportError: No module named MyModule
I already try this two methods :
subprocess.call()
os.system()
Any Idea ?
What I usually do and what I usually see other programmers do is that they import their libraries first, before they even put any line of code. This is also helpful to see what libraries you're working with since the beginning of the code.
import subprocess
import Mymodule
script = "command"
subprocess.call = (script, shell = True)
Please let me know if this fix the issue, here's also a cool article that might help you.
I'm trying to run a python program (specifically, I'm running manimgl, but I don't think that matters here) and the first line reads from manim_imports_ext import *. However, I am getting the error ModuleNotFoundError: No module named 'manim_imports_ext' even though I have verified that the file manim_imports_ext.py is in the current working directory. The program itself is in a subdirectory, but that doesn't seem relevant.
Any help would be greatly appreciated; it seems like I must be doing something dumb.
I am trying to write a code that allows me to make a keyboard press to trigger an output. I am trying to use the keyboard module to do this, but every time I try to run it I get an error that says:
File "/Users/julietdenapoli/Desktop/keyboard.py", line 10, in
from msvcrt import getch ModuleNotFoundError: No module named 'msvcrt'
I kept noticing that the issue was coming from the import keyboard, so I literally just tried to run a one line code:
import keyboard
And I still get that same error. I did pip install keyboard, not really sure why I am running into this error?
I have a script called startup_launching.py, which does something like this:
import os
# launch chrome
os.startfile(r'C:\Program Files (x86)\google\chrome\application\chrome.exe')
To run this from the (windows) command line, I enter:
python "FILEPATH\startup_launching.py"
That works fine.
However, I have a separate script called threading.py, which does this:
import time, threading
def foo():
print(time.ctime())
threading.Timer(10, foo).start()
foo()
(which I found on stackoverflow).
When threading.py is saved in the same folder as startup_launching.py, it seems to interfere with startup_launching.py when I run it from the command line (e.g. one of the error messages is: module 'threading' has no attribute 'Timer').
When I move threading.py to another folder, startup_launching.py works fine again.
Can someone explain what's going on here? I assumed that entering:
python "FILEPATH\startup_launching.py"
in the command line would only look in startup_launching.py
Thanks!
you should rename your file so that it is not named threading.py, since it will be in the import path and will mask the actual built-in threading module, which the other script relies upon.
Name your module something other than threading.py because there is a built-in module named threading.py.
Don't call it threading.py. Also, check your python version, if it correspond to the tutorial that you were reading.