Pyside "module not found"
Answered
Hi all,
I recently started to dive into Python programming and want to create a gui using pyside. Pyside is installed on my system and via commandline I made sure it works.
Now I want to use it in Pycharm but every time I try to run the script I get the error "NameError: name 'PySide' is not defined"
I already had issues with installing PySide and when I try to install the module inside of Pycharm I get the same error (nmake not found). I thought by installing PySide on my system I would bypass the need to install it in Pycharm.
Anybody got an idea how to use Pyside?
Best
Jo
Please sign in to leave a comment.
Are you sure that you are pointed to the same interpreter in PyCharm that you used to install PySide? Take a look at Preferences -> Python Interpreter and see if pyside shows up in the installed packages.
Hi! Currently i have the same problem. I downloaded the CE and the pro version. It only works with the pro version of the 2017. The ce doesnt autocomplete or runs pyside. Is there ant restriction for the CE regarding this?
Hi Alenrqz21! There should be no difference between PE and CE, are you sure both use the same interpreter? Could you please specify what error do you receive in CE after run? Feel free to create a ticket in our bug tracker.
The same error happens. It says QtCore module not found. It is strange because it works perfect with the Pro. Also autocompeltation works fine in Pro with PySide. Only the CE have this issue.
Alenrqz21, do you use Anaconda interpreter?
Same EXACT problem.
PyCharm 2021.2.3 (CE)
Build #PC212.5457.59, built on October 19, 2021
File -> Settings -> Project: main.py -> Python Interpreter:
PySide2 5.15.2
qt.widgets 0.18 (in case it matters)
my code(gui.py):
main.py:
import gui.py
gui.run()
Terminal (in PyCharm):
python main.py
PS F:\my_file> python main.py
Traceback (most recent call last):
File "main.py", line 9, in <module>
import gui
File "F:\my_file\gui.py", line 1, in <module>
from PySide2.QtWidgets import QApplication, QMainWindow
ImportError: No module named PySide2.QtWidgets
PS F:\my_file>
Hello,
could you please run the code out of PyCharm with the same interpreter? Will you get the same error?
For more information on how to run your code from the terminal outside of IDE, please see the following article:
https://docs.python.org/3/using/cmdline.html#command-line
If you're using virtualenv interpreter in PyCharm, you may need to activate it in the command line prior to running your code:
https://virtualenv.pypa.io/en/latest/user_guide.html#activators
Yes, same error from the command line.
I'm not using virtualenv interpreter.
All my other python code works fine. It's just PySide.
From CMD:
F:\>cd my_directory\
F:\my_directory>python main.py
Traceback (most recent call last):
File "main.py", line 9, in <module>
import gui
File "F:\my_directory\gui.py", line 1, in <module>
from PySide2.QtWidgets import QApplication, QMainWindow
ImportError: No module named PySide2.QtWidgets
F:\my_directory>
I then realized my Python version in PATH was 2.7, so I changed it to 3.7.8
C:\Users\me>python --version
Python 3.7.8
C:\Users\me>f:
F:\>cd my_directory
F:\my_directory>python main.py
Dec 02 2021 082220
main.py:81: DeprecationWarning: time.clock has been deprecated in Python 3.3 and will be removed from Python 3.8: use time.perf_counter or time.process_time instead
start = clock()
========================================
main.py:78: DeprecationWarning: time.clock has been deprecated in Python 3.3 and will be removed from Python 3.8: use time.perf_counter or time.process_time instead
return secondsToStr(clock())
Traceback (most recent call last):
File "main.py", line 100, in <module>
process()
File "main.py", line 83, in process
log("Start Program")
File "main.py", line 65, in log
print(now() + "\t" + s)
File "main.py", line 78, in now
return secondsToStr(clock())
File "main.py", line 58, in secondsToStr
reduce(lambda ll, b: divmod(ll[0], b) + ll[1:],
NameError: name 'reduce' is not defined
main.py:73: DeprecationWarning: time.clock has been deprecated in Python 3.3 and will be removed from Python 3.8: use time.perf_counter or time.process_time instead
end = clock()
Error in atexit._run_exitfuncs:
Traceback (most recent call last):
File "main.py", line 75, in endlog
log("End Program", secondsToStr(elapsed))
File "main.py", line 58, in secondsToStr
reduce(lambda ll, b: divmod(ll[0], b) + ll[1:],
NameError: name 'reduce' is not defined
F:\my_directory>
At this point I multi-line commented the deprecated code in main.py, which was simply being used to report the process time.
This resulted in the code running fine in cmd.
Then I tried it again in PyCharm and it also worked fine.
# THE FIX
So, the problem was resolved by