Home > Mobile >  why does it give me error while importing sys module
why does it give me error while importing sys module

Time:01-05

so i am making a desktop app and i have been coming up by this error

SyntaxError: invalid syntax
>>> & C:/Users/AppData/Local/Microsoft/WindowsApps/python3.9.exe c:/Users/Desktop/App/main.py
  File "<stdin>", line 1
    & C:/Users/AppData/Local/Microsoft/WindowsApps/python3.9.exe c:/Users/Desktop/App/main.py
    ^
SyntaxError: invalid syntax
>>>

this is the code

import sys 
from PyQt5 import QtWidgets #pyqt5 module 
from PyQt5.QtWidgets import QApplication, QMainWindow #just to save some time 
from PyQt5.QtGui import QIcon                         # ||  ||  ||  ||  ||  ||

def window(): # the main function
    app = QApplication(sys.argv) # its argument magik
    win = QMainWindow() # its like tkinter.tk() function but in pyqt
    win.setGeometry(1200, 300, 700, 700) # sets position of ui
    win.setToolTip("name asker bruh ") # sets tooltip
    win.setWindowTitle("name asker! 1.0.1") # name of ui 
    win.setWindowIcon(QIcon("Chrome.jfif")) # icon hehehe
    labl_name = QtWidgets.QLabel(win) 
    labl_name.setText("enter your first name:")
    labl_name.adjustSize()
    labl_name.move(72, 90)
    labl_mname = QtWidgets.QLabel(win)
    labl_mname.setText("enter your middle name:")
    labl_mname.adjustSize()
    labl_mname.move(50, 130)

    labl_lname = QtWidgets.QLabel(win)
    labl_lname.setText("enter your last name:")
    labl_lname.adjustSize()
    labl_lname.move(75, 170)
    win.show()
    sys.exit(app.exec_())

window()

i am using pyqt5 module and the sys module but theres a syntax error while importing the sys module any solutions ? your answers will be appreciated

CodePudding user response:

Just run this in your cmd:

C:/Users/AppData/Local/Microsoft/WindowsApps/python3.9.exe c:/Users/Desktop/App/main.py

CodePudding user response:

Just run the python file in a windows command line and not in a python shell :)
Write the same command in windows cmd, open it in windows apps by searching for "cmd" and then write C:\Users\AppData\Local\Microsoft\WindowsApps\python3.9.exe C:\Users\<your-user>\Desktop\App\main.py

  •  Tags:  
  • Related