In 2020, the timer for python clock has stopped.
However, the CG industry is still using Python 2.7. (Because Maya, 3ds MAX, Houdini, etc. haven't been migrated yet, it can't be helped ...
The DCC tool is still Python2.7
, but the standalone Python tool doesn't have to be Python2.7
, so I'm using Python3.7
.
I'm using Python3.7
and thinking that pathlib
is convenient, but when I looked it up, a package was prepared for Python2.7
, so I tried to put it in Maya and use it. think.
If you want to use pathlib with Python 2.7, just do pip install pathlib
When using with Maya, install in PYTHONPATH
recognized by Maya with the -t
flag
In the case of I
Create a site-packages
folder in% USERPROFILE% \ Documents \ maya \ scripts
and install it there.
The module file recognizes PYTHONPATH
.
I prepare a bat for easy installation.
pip.bat
echo off
set PIP_INSTALL_PACKAGE=
set /P PIP_INSTALL_PACKAGE="enter the package to install:"
py -2.7 -m pip install %PIP_INSTALL_PACKAGE% -t site-packages
pause
Now that the installation is complete, I'll try using it.
import pathlib
pathlib.Path
# Result: <class 'pathlib.Path'> #
I can import it without any problems !!
pathlib.Path(os.getenv("MAYA_LOCATION")).parent
# Result: WindowsPath('C:/Program Files/Autodesk') #
list(pathlib.Path(os.getenv("MAYA_LOCATION")).iterdir())
# Result: [WindowsPath('C:/Program Files/Autodesk/Maya2020/assets'),WindowsPath('C:/Program Files/Autodesk/Maya2020/bin'),WindowsPath('C:/Program Files/Autodesk/Maya2020/brushImages'),WindowsPath('C:/Program Files/Autodesk/Maya2020/brushShapes'),WindowsPath('C:/Program Files/Autodesk/Maya2020/cmake'),WindowsPath('C:/Program Files/Autodesk/Maya2020/devkit'),WindowsPath('C:/Program Files/Autodesk/Maya2020/docs'),WindowsPath('C:/Program Files/Autodesk/Maya2020/Examples'),WindowsPath('C:/Program Files/Autodesk/Maya2020/ExternalWebBrowser'),WindowsPath('C:/Program Files/Autodesk/Maya2020/icons'),WindowsPath('C:/Program Files/Autodesk/Maya2020/include'),WindowsPath('C:/Program Files/Autodesk/Maya2020/lib'),WindowsPath('C:/Program Files/Autodesk/Maya2020/mkspecs'),WindowsPath('C:/Program Files/Autodesk/Maya2020/modules'),WindowsPath('C:/Program Files/Autodesk/Maya2020/plug-ins'),WindowsPath('C:/Program Files/Autodesk/Maya2020/plugins'),WindowsPath('C:/Program Files/Autodesk/Maya2020/presets'),WindowsPath('C:/Program Files/Autodesk/Maya2020/Python'),WindowsPath('C:/Program Files/Autodesk/Maya2020/PYTHON_LICENSE'),WindowsPath('C:/Program Files/Autodesk/Maya2020/PYTHON_README'),WindowsPath('C:/Program Files/Autodesk/Maya2020/qml'),WindowsPath('C:/Program Files/Autodesk/Maya2020/resources'),WindowsPath('C:/Program Files/Autodesk/Maya2020/scripts'),WindowsPath('C:/Program Files/Autodesk/Maya2020/support'),WindowsPath('C:/Program Files/Autodesk/Maya2020/synColor'),WindowsPath('C:/Program Files/Autodesk/Maya2020/translations')] #
You can find the contents of the directory with parent
and the contents of the directory with ʻiterdir`.
list(pathlib.Path(os.getenv("MAYA_LOCATION")).glob("Python/DLLs/*.pyd"))
# Result: [WindowsPath('C:/Program Files/Autodesk/Maya2020/python/dlls/bz2.pyd'),WindowsPath('C:/Program Files/Autodesk/Maya2020/python/dlls/pyexpat.pyd'),WindowsPath('C:/Program Files/Autodesk/Maya2020/python/dlls/select.pyd'),WindowsPath('C:/Program Files/Autodesk/Maya2020/python/dlls/unicodedata.pyd'),WindowsPath('C:/Program Files/Autodesk/Maya2020/python/dlls/winsound.pyd'),WindowsPath('C:/Program Files/Autodesk/Maya2020/python/dlls/_bsddb.pyd'),WindowsPath('C:/Program Files/Autodesk/Maya2020/python/dlls/_ctypes.pyd'),WindowsPath('C:/Program Files/Autodesk/Maya2020/python/dlls/_ctypes_test.pyd'),WindowsPath('C:/Program Files/Autodesk/Maya2020/python/dlls/_elementtree.pyd'),WindowsPath('C:/Program Files/Autodesk/Maya2020/python/dlls/_hashlib.pyd'),WindowsPath('C:/Program Files/Autodesk/Maya2020/python/dlls/_msi.pyd'),WindowsPath('C:/Program Files/Autodesk/Maya2020/python/dlls/_multiprocessing.pyd'),WindowsPath('C:/Program Files/Autodesk/Maya2020/python/dlls/_socket.pyd'),WindowsPath('C:/Program Files/Autodesk/Maya2020/python/dlls/_sqlite3.pyd'),WindowsPath('C:/Program Files/Autodesk/Maya2020/python/dlls/_ssl.pyd'),WindowsPath('C:/Program Files/Autodesk/Maya2020/python/dlls/_testcapi.pyd')] #
You can also use glob!
Since I was able to use pathlib
safely, I will add it to the in-house library and actively use it.
It would be nice if it was Python3.7
by the time Maya2021
came out, but I think that the festival of putting in the existing tools will start after the migration, so it's a shame ...
I'll get used to it a little in preparation for the upcoming Python 3.7
.
Recommended Posts