Last week I started learning Python for Maya, following the 'CGCircuit - Learn Python Inside Maya'.
Now I'm trying to make a simple UI for Maya2020 using Qt. The tutorial itself is pretty outdated, a lot has changed since Maya2015.
I checked a lot of forums and it seems I’m not the only one having problems. This is what I learned so far:
Qt designer is not a part of Maya anymore, so I downloaded Qt Creator 4.14.0 (Community)
I used pip to install: shiboken2-5.15.2-5.15.2-cp35.cp36.cp37.cp38.cp39-none-win_amd64.whl
If I'm correct, Maya2020 has Pyside2 pr-installed, but I also Installed Pyside2 on Windows10
QtGui.QDialog is replaced by QWidget
Currently I ‘m using Python 2.7.17 on my Windows system, but I also have Python3.8 available in my Environment Variable
When I call the py script inside Maya, like this:
import geomGenerator
reload(geomGenerator)
geomGenerator.getMayaWindow()
geomGenerator.run()
I get this error:
Error: NameError: file C:/Users/12213119/Documents/maya/2020/scripts\geomGenerator.py line 12: global name 'shiboken2' is not defined #
Not sure what this means or how I can solve it. I looked all over the internet, please let me know what I'm doing wrong. Thx in regard.
from PySide2 import QtGui, QtCore, QtUiTools, QtWidgets
from shiboken2 import wrapInstance
import maya.cmds as mc
import maya.OpenMayaUI as omui
def getMayaWindow():
""" pointer to the maya main window
"""
ptr = omui.MQtUtil.mainWindow()
if ptr is not None:
return shiboken2.wrapInstance2(long(ptr), QtWidgets.QWidget)
def run():
""" builds our UI
"""
global win
win = GeometryGenerator(parent=getMayaWindow())
win.show()
class GeometryGenerator(QtWidgets.QWidget):
def __init__(self,parent=None):
super(GeometryGenerator,self).__init__(parent)
I guess you need to run you script with python that comes with Maya, and use pip that comes with maya to install packages.
Related
I have written codes but it's showing cannot import pygame module
Download pygame from here: http://www.pygame.org/download.shtml
If you are not sure which version of python you are running, execute the following code in your shell:
import sysconfig
version = sysconfig.get_python_version()
print(version) #Python3
print version #Python2
Usually, Python3 will also accept the print command without brackets, so using sysconfig is the safest way. Sysconfig will also tell you which minor version you are using (such as 3.4.5)
Once you have download pygame, tryimport pygame in your shell. If this does not work, type help('modules'). This will now list all your modules. If pygame is not in there, check in which folder all other modules are saved and move the pygame module to that file path.
You can also use sysconfig to display all the file paths python is using:
import sysconfig
paths = sysconfig.get_paths()
print(paths) #For Python2, see print method above
I don't quite understand what you mean with "And make games", but the pygame website has a great documentary and some example codes to help you learn progamming with the pygame module.
Hope I could help,
Narusan
I am currently in the process of getting the documentation of my code online via read-the-docs, however, getting read-the-docs to process my PyQt4 dependent modules seems problematic.
My project has the following structure:
pkg
pkg/__init__.py
pkg/modules/
pkg/modules/__init__.py
pkg/modules/somemodules.py
pkg/gui/__init__.py
pkg/gui/someGUImodules.py
I am using sphinx-autodoc to build a html representation of the docstring of the different modules. On my local machine everything works fine, however, since I need to mock PyQt4 on read-the-docs, I ran into the following problem: In one of my GUI classes, I subclass QtGui.QDialog via
class listSelectorDialog(QtGui.QDialog):
def __init__(self,parent,List):
super(listSelectorDialog,self).__init__(parent)
and listSelectorDialog via
class advancedListSelectorDialog(listSelectorDialog):
def __init__(self,parent,List):
super(advancedListSelectorDialog,self).__init__(parent,List)
Mocking QtGui will result in read-the-docs telling me:
class advancedListSelectorDialog(listSelectorDialog):
TypeError: Error when calling the metaclass bases
str() takes at most 1 argument (3 given)
and hence crashing. I've tried to build my package into a virtual environment by selecting
Install your project inside a virtualenv using setup.py install
however, it turns out even though PyQt4 is listed in pip, you can not install it, see https://superuser.com/questions/679298/how-to-install-pyqt4-and-what-are-the-practical-differences-between-pyqt4-and-py.
The only workaround I've found so far is to not load the GUI modules if the environment is RTD and leave out the documentation of the GUI modules, however this should not be the final solution. Thanks.
I had a similar problem with PyQt5/py3 (a metaclass conflict with MagickMock). My workaround is to manually mock the module in conf.py instead of using unittest.mock:
class PyQt5:
#staticmethod
def qVersion():
return '5.0.0'
class QtCore:
class QObject:
pass
# etc...
sys.modules['PyQt5'] = PyQt5
This makes the import / metaclass conflict problem disappear. Unfortunately autodoc still doesn't work (no output), though the builds pass...
Tedious of course.
I installed kivy on my Window 7, Python 2.7. When I run the following code:
import kivy
from kivy.app import App
from kivy.uix.label import Label
class MyApp(App):
def build(self):
return Label(text='Hello World!')
if __name__ == '__main__':
MyApp().run()
it gives the following error:
Unable to get a Window, abort.
I tried on Python 3.4, same error.
There is an option that sdl2 can't find dlls needed to load *.png
Try to find libpng16-16.dll
on my PC is here: C:\Python27\share\gstreamer\bin
Add it to PATH
set PATH=C:\Python27\share\gstreamer\bin;%PATH%
This is temporary solution but it works for me
If you use Windows 10 then you may have two windows 10 installed on that same laptop which then has made it difficult for Python, Kivy and Kivmd to find the Windows to execute the program with so it gives an error.
That is why this commonly happens to partitioned laptops so check your laptop again to know how many windows are installed and delete one of the windows or you can also format your laptop properly to solve these issues. In my case my laptop was formatted.
So I thought I'd toy around and try and learn Kivy, as it looks interesting. I have just started trying to get one of their examples working:
from kivy.app import App
from kivy.uix.widget import Widget
class MyPaintWidget(Widget):
pass
class MyPaintApp(App):
def build(self):
return MyPaintWidget()
if __name__ == '__main__':
MyPaintApp().run()
I get the following error:
C:\Kivy-1.8.0-py2.7-win32>python paint.py
Traceback (most recent call last):
File "paint.py", line 1, in <module>
from kivy.app import App
ImportError: No module named kivy.app
I have installed the latest version of Kivy. I see "app.py in the C:\Kivy-1.8.0-py2.7-win32\kivy\kivy folder.
Also, here is my PYTHONPATH:
>>> import sys
>>> for n in sys.path:
... print n
...
C:\Kivy-1.8.0-py2.7-win32\Python27\lib\site-packages\setuptools-2.0.1-py2.7.egg
C:\Kivy-1.8.0-py2.7-win32\Python27\lib\site-packages\pywin32-218-py2.7-win32.egg
C:\Kivy-1.8.0-py2.7-win32\Python27\lib\site-packages\plyer-1.1.2-py2.7.egg
C:\Kivy-1.8.0-py2.7-win32\Python27\lib\site-packages\kivy_garden-0.1.1-py2.7.egg
C:\Kivy-1.8.0-py2.7-win32\Python27\lib\site-packages\requests-2.2.1-py2.7.egg
C:\Kivy-1.8.0-py2.7-win32\Python27\python27.zip
C:\Kivy-1.8.0-py2.7-win32\Python27\DLLs
C:\Kivy-1.8.0-py2.7-win32\Python27\lib
C:\Kivy-1.8.0-py2.7-win32\Python27\lib\plat-win
C:\Kivy-1.8.0-py2.7-win32\Python27\lib\lib-tk
C:\Kivy-1.8.0-py2.7-win32\Python27
C:\Kivy-1.8.0-py2.7-win32\Python27\lib\site-packages
Any help would be greatly appreciated. Thank you.
I ran into this error message when I named the script kivy.py, because python looks first in the current directory to fill the dependency, so it never sees the real kivy package.
Renaming the script fixed it for me.
The name of the folder or file cannot be kivy or kivy.py. You need to rename it to another name and it will run ok.
So, I figured it out....I was not being very smart. I'm new to Kivy and I'll answer this for anyone else that is as green as I am. You can't just run this as a python program, doh.
Follow instructions [here] (http://kivy.org/docs/installation/installation-windows.html#start-a-kivy-application) and all will be right with the world.
If you installed kivy using pip you need to add the packages to your environment. In Windows Command Prompt do
pip show kivy
~Take note of the Location of the module.
Next you can do 1 of two things.
Configure any python files you write to refer to the location of your module with sys, use this tutorial for more info: https://kivy.org/docs/guide/environment.html
Add the location you found above to your PATH (Windows): https://www.computerhope.com/issues/ch000549.htm
2 Worked for me.
I was also facing the same issue while running sample app.
I followed simple steps given in : https://kivy.org/doc/stable/gettingstarted/installation.html#install-pip
It worked for me.
Create the virtual environment
Activate the virtual environment.
Install Kivy
run your .py file
I know I am too late but I hope this will help others, I just did not run it from the command prompt, I opened the python code in my python shell and then pressed run 'F5' and it worked for me.
If you're using a virtual environment (venv), make sure you're targetting the the correct Python interpreter. See here for how to to change to the venv interpreter in IntelliJ
Im completely new to pygame. after installing it and looking at a tutorial, the first code block i ran (from the tutorial) took me to the pygame modlule, and said that pygame.base could not be found.
it couldn't find any of these at all:
from pygame.base import *
from pygame.constants import *
from pygame.version import *
from pygame.rect import Rect
from pygame.compat import geterror
import pygame.rwobject
import pygame.surflock
import pygame.color
that's from the pygame module.
I looked in both the pygame files that were installed and saw files with those names, though i could not open them (unknown file type)
i installed the python 2.7 binary for windows version of pygame, and used the installer. everything looks like it's in the right place as far as i can tell.
It doesn't seem that you have pygame properly installed. Can you even successfully run import pygame?
Are you sure you only have one copy of python installed?