- 2016.10.07 Friday
- Maya Python version
-
import sys
print (sys.version)Maya 2016
2.7.6 (default, May 8 2014, 03:23:20) [MSC v.1700 64 bit (AMD64)]
Maya 2017
2.7.11 (default, Dec 21 2015, 22:48:54) [MSC v.1700 64 bit (AMD64)]
微妙にちがっている。
とにかく2.7後半系
------------------------------------------------Mayaとは別でpython2.7.6 install------------------------------------------
win
https://www.python.org/downloads/windows/
- Python 2.7.6 - 2013-11-10
- Download Windows x86 MSI program database
- Download Windows x86 MSI Installer
- Download Windows X86-64 MSI program database
- Download Windows X86-64 MSI Installer
- Download Windows help file
- インストールが終わったら環境変数にパスを追加する.
参考:Windows 環境変数 Path の設定方法PATH = $PATH;C:¥Python27;C:¥Python27¥Scripts;
コマンドプロンプトで
> phython
と入力して,Python を起動する.
Python 2.7.6 (default, Nov 10 2013, 19:24:18) [MSC v.1500 32 bit (Intel)] on win 32 Type "help", "copyright", "credits" or "license" for more information. >>>
が表示されることを確認する. Python の使い方などについては,参考 web ページのチュートリアルを参照されたい.
参考 web ページ
setuptools (easy_install)
Python のパッケージをコマンドプロンプトからインストールできる便利なツールをインストールする.
https://trac.edgewall.org/wiki/TracPlugins
C:¥Python27>ez_setup.py
Downloading http://pypi.python.org/packages/2.7/s/setuptools/setuptools-0.6c11-py2.7.egg
Processing setuptools-0.6c11-py2.7.egg
Copying setuptools-0.6c11-py2.7.egg to c:¥python27¥lib¥site-packages
Adding setuptools 0.6c11 to easy-install.pth file
Installing easy_install-script.py script to C:¥Python27¥Scripts
Installing easy_install.exe script to C:¥Python27¥Scripts
Installing easy_install.exe.manifest script to C:¥Python27¥Scripts
Installing easy_install-2.7-script.py script to C:¥Python27¥Scripts
Installing easy_install-2.7.exe script to C:¥Python27¥Scripts
Installing easy_install-2.7.exe.manifest script to C:¥Python27¥ScriptsInstalled c:¥python27¥lib¥site-packages¥setuptools-0.6c11-py2.7.egg
Processing dependencies for setuptools==0.6c11
Finished processing dependencies for setuptools==0.6c11C:¥Python27>
http://uxmilk.jp/12691
pipのインストール方法
pipはPython 2.7.9以降、Python 3.4以降のバージョンにはデフォルトでインストールされています。
2.7.6にはインストールされていないので、以下を実行してください。
1. get-pip.pyをダウンロードしてください。https://gist.github.com/whaison/b20a7cb50f0d4c0033e765fe41f6ae74
2. ファイルをダウンロードしたディレクトリに移動し以下のコマンドを実行してください。これでpipのインストールは完了です。
pipのアップデート方法
pipがデフォルトでインストールされている場合もpipのバージョンが低い可能性がありますので、念のためpipをアップデートした方がいいでしょう。以下のコマンドでアップデートすることができます。
Linux, OS Xの場合
Windowsの場合
1$ sudo python -m pip install -U pip9以降、Python 3.4以降のバージョンにはデフォルトでインストールされています。インストールされていない場合は、以下を実行してください。
1. get-pip.pyをダウンロードしてください。https://gist.github.com/whaison/83dbf14015bcd2f937bba8509a076428
2. ファイルをダウンロードしたディレクトリに移動し以下のコマンドを実行してください。これでpipのインストールは完了です。
pipのアップデート方法
pipがデフォルトでインストールされている場合もpipのバージョンが低い可能性がありますので、念のためpipをアップデートした方がいいでしょう。以下のコマンドでアップデートすることができます。
Linux, OS Xの場合
Windowsの場合
1$ sudo python -m pip install -U pipC:¥Python27>python get-pip.py
Collecting pip
c:¥users¥whaison¥appdata¥local¥temp¥tmpojibcv¥pip.zip¥pip¥_vendor¥requests¥packages¥urllib3¥util¥ssl_.py:318: SNIMissingWarning: An HTTPS request has been made, but the SNI (Subject Name Indication) extension to TLS is not available on this platform. This may cause the server to present an incorrect TLS certificate, which can cause validation failures. You can upgrade to a newer version of Python to solve this. For more information, see https://urllib3.readthedocs.io/en/latest/security.html#snimissingwarning.
c:¥users¥whaison¥appdata¥local¥temp¥tmpojibcv¥pip.zip¥pip¥_vendor¥requests¥packages¥urllib3¥util¥ssl_.py:122: InsecurePlatformWarning: A true SSLContext object is not available. This prevents urllib3 from configuring SSL appropriately and may cause certain SSL connections to fail. You can upgrade to a newer version of Python to solve this. For more information, see https://urllib3.readthedocs.io/en/latest/security.html#insecureplatformwarning.
Downloading pip-9.0.1-py2.py3-none-any.whl (1.3MB)
100% |################################| 1.3MB 322kB/s
Collecting wheel
Downloading wheel-0.29.0-py2.py3-none-any.whl (66kB)
100% |################################| 71kB 645kB/s
Installing collected packages: pip, wheel
Successfully installed pip-9.0.1 wheel-0.29.0
c:¥users¥whaison¥appdata¥local¥temp¥tmpojibcv¥pip.zip¥pip¥_vendor¥requests¥packages¥urllib3¥util¥ssl_.py:122: InsecurePlatformWarning: A true SSLContext object is not available. This prevents urllib3 from configuring SSL appropriately and may cause certain SSL connections to fail. You can upgrade to a newer version of Python to solve this. For more information, see https://urllib3.readthedocs.io/en/latest/security.html#insecureplatformwarning.C:¥Python27>
Python のコーディング規約 PEP8 に準拠する http://qiita.com/ynakayama/items/8616f4c0c6e372de9a42
Python のソースコードを自動で PEP8 に準拠させるツール autopep8
http://momijiame.tumblr.com/post/42168625947/Python のソースコードを自動で PEP8 に準拠させるツール autopep8
C:¥Python27>pip install pep8
Collecting pep8
c:¥python27¥lib¥site-packages¥pip¥_vendor¥requests¥packages¥urllib3¥util¥ssl_.py:318: SNIMissingWarning: An HTTPS request has been made, but the SNI (Subject Name Indication) extension to TLS is not available on this platform. This may cause the server to present an incorrect TLS certificate, which can cause validation failures. You can upgrade to a newer version of Python to solve this. For more information, see https://urllib3.readthedocs.io/en/latest/security.html#snimissingwarning.
SNIMissingWarning
c:¥python27¥lib¥site-packages¥pip¥_vendor¥requests¥packages¥urllib3¥util¥ssl_.py:122: InsecurePlatformWarning: A true SSLContext object is not available. This prevents urllib3 from configuring SSL appropriately and may cause certain SSL connections to fail. You can upgrade to a newer version of Python to solve this. For more information, see https://urllib3.readthedocs.io/en/latest/security.html#insecureplatformwarning.
InsecurePlatformWarning
Downloading pep8-1.7.0-py2.py3-none-any.whl (41kB)
100% |################################| 51kB 382kB/s
Installing collected packages: pep8
Successfully installed pep8-1.7.0
c:¥python27¥lib¥site-packages¥pip¥_vendor¥requests¥packages¥urllib3¥util¥ssl_.py:122: InsecurePlatformWarning: A true SSLContext object is not available. This prevents urllib3 from configuring SSL appropriately and may cause certain SSL connections to fail. You can upgrade to a newer version of Python to solve this. For more information, see https://urllib3.readthedocs.io/en/latest/security.html#insecureplatformwarning.
InsecurePlatformWarningC:¥Python27>
C:¥Python27>pep8 --version
1.7.0はいった。
pep8準拠してないpyファイルをようい
none_pep8.py
#!/usr/bin/env python
# -*- coding: utf-8 -*-def foo():
msgs=['Hello','World!!']
print ','.join(msgs)if __name__ == '__main__':
foo()チェックしてみる
C:¥Python27¥Scripts¥non_pep8>pep8 non_pep8.py
non_pep8.py:4:1: E302 expected 2 blank lines, found 1
non_pep8.py:5:9: E225 missing whitespace around operator
non_pep8.py:5:18: E231 missing whitespace after ','
non_pep8.py:9:10: W292 no newline at end of fileC:¥Python27¥Scripts¥non_pep8>
4, 5, 9 行目に問題があるらしいことがわかった。 後はエラーメッセージを元に修正していけば良い。
とはいえ、修正対象のソースコードがあまりにも多いときには、全てを手動でチマチマ直していく作業はあまりに大変そう。
そんな大変な作業を肩代わりしてくれるツールとして autopep8 がある。C:¥Python27¥Scripts¥non_pep8>pip install autopep8
Collecting autopep8
c:¥python27¥lib¥site-packages¥pip¥_vendor¥requests¥packages¥urllib3¥util¥ssl_.py:318: SNIMissingWarning: An HTTPS request has been made, but the SNI (Subject Name Indication) extension to TLS is not available on this platform. This may cause the server to present an incorrect TLS certificate, which can cause validation failures. You can upgrade to a newer version of Python to solve this. For more information, see https://urllib3.readthedocs.io/en/latest/security.html#snimissingwarning.
SNIMissingWarning
c:¥python27¥lib¥site-packages¥pip¥_vendor¥requests¥packages¥urllib3¥util¥ssl_.py:122: InsecurePlatformWarning: A true SSLContext object is not available. This prevents urllib3 from configuring SSL appropriately and may cause certain SSL connections to fail. You can upgrade to a newer version of Python to solve this. For more information, see https://urllib3.readthedocs.io/en/latest/security.html#insecureplatformwarning.
InsecurePlatformWarning
Downloading autopep8-1.2.4-py2.py3-none-any.whl (41kB)
100% |################################| 51kB 453kB/s
Requirement already satisfied: pep8>=1.5.7 in c:¥python27¥lib¥site-packages (from autopep8)
Installing collected packages: autopep8
Successfully installed autopep8-1.2.4C:¥Python27¥Scripts¥non_pep8>
C:¥Python27¥Scripts¥non_pep8>autopep8 --version
autopep8 1.2.4OK
C:¥Python27¥Scripts¥non_pep8>autopep8 -i non_pep8.py
チェックしてみる
C:¥Python27¥Scripts¥non_pep8>pep8 non_pep8.py
C:¥Python27¥Scripts¥non_pep8>
なんにもエラーがでなくなった。
Code
#!/usr/bin/env python
# -*- coding: utf-8 -*-
def foo():
msgs = ['Hello', 'World!!']
print ','.join(msgs)if __name__ == '__main__':
foo()ところで、それまで PEP8 に準拠していなかったプロジェクトを準拠させようとしたときなんか、色んなソースコードのファイルで膨大な数の警告が出てうんざりすることになるはず。
だとすると、ディレクトリを再帰的に調べながら pep8 で警告が出ているソースコードのファイルに対して autopep8 にかけまくれると便利なんじゃなかろうか。
そこで、以下のワンライナー。のまえに
こんな階層をもったエラーだしとく
C:¥Python27¥Scripts¥non_pep8>pep8 .
.¥non_pep8.py:4:1: E302 expected 2 blank lines, found 1
.¥non_pep8.py:5:9: E225 missing whitespace around operator
.¥non_pep8.py:5:18: E231 missing whitespace after ','
.¥non_pep8.py:9:10: W292 no newline at end of file
.¥nest1¥non_pep8_1.py:4:1: E302 expected 2 blank lines, found 1
.¥nest1¥non_pep8_1.py:5:9: E225 missing whitespace around operator
.¥nest1¥non_pep8_1.py:5:18: E231 missing whitespace after ','
.¥nest1¥non_pep8_1.py:9:10: W292 no newline at end of file
.¥nest1¥nest2¥non_pep8_2.py:4:1: E302 expected 2 blank lines, found 1
.¥nest1¥nest2¥non_pep8_2.py:5:9: E225 missing whitespace around operator
.¥nest1¥nest2¥non_pep8_2.py:5:18: E231 missing whitespace after ','
.¥nest1¥nest2¥non_pep8_2.py:9:10: W292 no newline at end of fileC:¥Python27¥Scripts¥non_pep8>
C:¥Python27¥Scripts¥non_pep8>pep8 --help
Usage: pep8 [options] input ...Options:
--version show program's version number and exit
-h, --help show this help message and exit
-v, --verbose print status messages, or debug with -vv
-q, --quiet report only file names, or nothing with -qq
-r, --repeat (obsolete) show all occurrences of the same error
--first show first occurrence of each error
--exclude=patterns exclude files or directories which match these comma
separated patterns (default:
.svn,CVS,.bzr,.hg,.git,__pycache__,.tox)
--filename=patterns when parsing directories, only check filenames matching
these comma separated patterns (default: *.py)
--select=errors select errors and warnings (e.g. E,W6)
--ignore=errors skip errors and warnings (e.g. E4,W) (default:
E121,E123,E126,E226,E24,E704)
--show-source show source code for each error
--show-pep8 show text of PEP 8 for each error (implies --first)
--statistics count errors and warnings
--count print total number of errors and warnings to standard
error and set exit code to 1 if total is not null
--max-line-length=n set maximum allowed line length (default: 79)
--hang-closing hang closing bracket instead of matching indentation of
opening bracket's line
--format=format set the error format [default|pylint|<custom>]
--diff report changes only within line number ranges in the
unified diff received on STDINTesting Options:
--benchmark measure processing speedConfiguration:
The project options are read from the [pep8] section of the tox.ini
file or the setup.cfg file located in any parent folder of the path(s)
being processed. Allowed options are: exclude, filename, select,
ignore, max-line-length, hang-closing, count, format, quiet, show-
pep8, show-source, statistics, verbose.--config=path user config file location
C:¥Python27¥Scripts¥non_pep8>
おとくなワンライナー
$ pep8 . | cut -d: -f1 | sort | uniq | xargs autopep8 -i
あらうごかない
'cut' は、内部コマンドまたは外部コマンド、
操作可能なプログラムまたはバッチ ファイルとして認識されていません。C:¥Python27¥Scripts¥non_pep8>pip install cut
Collecting cut
c:¥python27¥lib¥site-packages¥pip¥_vendor¥requests¥packages¥urllib3¥util¥ssl_.py:318:SNIMissingWarning: An HTTPS request has been made,
but the SNI (Subject Name Indication) extension to TLS is not available on this platform.
This may cause the server to present an incorrect TLS certificate,
which can cause validation failures. You can upgrade to a newer version of Python to solve this.
For more information, see https://urllib3.readthedocs.io/en/latest/security.html#snimissingwarning.
SNIMissingWarning
c:¥python27¥lib¥site-packages¥pip¥_vendor¥requests¥packages¥urllib3¥util¥ssl_.py:122:InsecurePlatformWarning:
A true SSLContext object is not available.
This prevents urllib3 from configuring SSL appropriately and may cause certain SSL connections to fail.
You can upgrade to a newer version of Python to solve this.
For more information,
see https://urllib3.readthedocs.io/en/latest/security.html#insecureplatformwarning.
InsecurePlatformWarning Could not find a version that satisfies the requirement cut (from versions: ) No matching distribution found for cut
C:¥Python27¥Scripts¥non_pep8>
OK
URL1
URL2
>>> import urllib3 >>> urllib3.disable_warnings()
Alternatively you can capture the warnings with the standard
logging
module:>>> logging.captureWarnings(True)
$ pep8 . | sort | uniq | xargs autopep8 -i
'uniq' は、内部コマンドまたは外部コマンド、
操作可能なプログラムまたはバッチ ファイルとして認識されていません。C:¥Python27¥Scripts¥non_pep8>pip install uniq
Collecting uniq
c:¥python27¥lib¥site-packages¥pip¥_vendor¥requests¥packages¥urllib3¥util¥ssl_.py:318: SNIMissingWarning: An HTTPS request has been made, but the SNI (Subject Name Indication) extension to TLS is not available on this platform. This may cause the server to present an incorrect TLS certificate, which can cause validation failures. You can upgrade to a newer version of Python to solve this. For more information, see https://urllib3.readthedocs.io/en/latest/security.html#snimissingwarning.
SNIMissingWarning
c:¥python27¥lib¥site-packages¥pip¥_vendor¥requests¥packages¥urllib3¥util¥ssl_.py:122: InsecurePlatformWarning: A true SSLContext object is not available. This prevents urllib3 from configuring SSL appropriately and may cause certain SSL connections to fail. You can upgrade to a newer version of Python to solve this. For more information, see https://urllib3.readthedocs.io/en/latest/security.html#insecureplatformwarning.
InsecurePlatformWarning
Downloading uniq-1.2.0.20.tar.gz (182kB)
100% |################################| 184kB 660kB/s
Complete output from command python setup.py egg_info:
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "c:¥users¥whaison¥appdata¥local¥temp¥pip-build-afhyyj¥uniq¥setup.py", line 86, in <module>
version=get_version(),
File "c:¥users¥whaison¥appdata¥local¥temp¥pip-build-afhyyj¥uniq¥setup.py", line 50, in get_version
num_commits = get_cr_num(first_release_data)
File "c:¥users¥whaison¥appdata¥local¥temp¥pip-build-afhyyj¥uniq¥setup.py", line 67, in get_cr_num
process = subprocess.Popen(command, stdout=subprocess.PIPE)
File "c:¥python27¥lib¥subprocess.py", line 709, in __init__
errread, errwrite)
File "c:¥python27¥lib¥subprocess.py", line 957, in _execute_child
startupinfo)
WindowsError: [Error 2] 指定されたファイルが見つかりません。----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in c:¥users¥whaison¥appdata¥local¥temp¥pip-build-afhyyj¥uniq¥C:¥Python27¥Scripts¥non_pep8>
ok
$ pep8 . | sort | xargs autopep8 -i
'xargs' は、内部コマンドまたは外部コマンド、
操作可能なプログラムまたはバッチ ファイルとして認識されていません。C:¥Python27¥Scripts¥non_pep8>pip install xargs
Collecting xargs
c:¥python27¥lib¥site-packages¥pip¥_vendor¥requests¥packages¥urllib3¥util¥ssl_.py:318: SNIMissingWarning: An HTTPS request has been made, but the SNI (Subject Name Indication) extension to TLS is not available on this platform. This may cause the server to present an incorrect TLS certificate, which can cause validation failures. You can upgrade to a newer version of Python to solve this. For more information, see https://urllib3.readthedocs.io/en/latest/security.html#snimissingwarning.
SNIMissingWarning
c:¥python27¥lib¥site-packages¥pip¥_vendor¥requests¥packages¥urllib3¥util¥ssl_.py:122: InsecurePlatformWarning: A true SSLContext object is not available. This prevents urllib3 from configuring SSL appropriately and may cause certain SSL connections to fail. You can upgrade to a newer version of Python to solve this. For more information, see https://urllib3.readthedocs.io/en/latest/security.html#insecureplatformwarning.
InsecurePlatformWarning
Could not find a version that satisfies the requirement xargs (from versions: )
No matching distribution found for xargsC:¥Python27¥Scripts¥non_pep8>
$ pep8 . | sort | autopep8 -i
pep8 . | cut -d: -f1 | sort | uniq | xargs autopep8 -i
'cut' は、内部コマンドまたは外部コマンド、
操作可能なプログラムまたはバッチ ファイルとして認識されていません。かわらんな。
http://note.chiebukuro.yahoo.co.jp/detail/n195202
- Python 2.7.6 - 2013-11-10
- | whaison | MayaPython | 16:59 | comments(0) | - | pookmark |
- 2016.10.04 Tuesday
- "basenameEx" is mel Only but , "basenameEx_python" is python ver
-
"basenameEx" is mel Only but , "basenameEx_python" is python ver
http://me.autodesk.jp/wam/maya/docs/Maya2010/Commands/basenameEx.html
Mel
basenameEx("/usr/people/gamera/gamera.mel"); // Result: gamera //
Python
basenameEx("/usr/people/gamera/gamera.mel")
// Result: gamera //
- | whaison | MayaPython | 10:49 | comments(0) | - | pookmark |
- 2016.10.03 Monday
- "stringArrayRemove" is mel Only but , "stringArrayRemove_python" is python ver
-
"stringArrayRemove" is mel Only but ,
"stringArrayRemove_python" is python verhttp://me.autodesk.jp/wam/maya/docs/Maya2010/Commands/stringArrayRemove.html
mel
string $list[] = { "a", "b", "c", "d", "e", "f", "g" }; string $items[] = { "a", "c", "e", "g" }; string $diff[] = stringArrayRemove($items, $list); // Result : { b, d, f } //
python
list = [ "a", "b", "c", "d", "e", "f", "g" ]
items = [ "a", "c", "e", "g" ]
diff = stringArrayRemove_python(items, list)
print ("Result : "+str(diff))Result : ['b', 'd', 'f']
code
- | whaison | MayaPython | 14:39 | comments(0) | - | pookmark |
- 2016.09.29 Thursday
- Anim_File_Export_class.py GoodOutPut!!
-
Anim_File_Export_class.py GoodOutPut!!
- | whaison | MayaPython | 16:03 | comments(0) | - | pookmark |
- 2016.09.27 Tuesday
- Ueta CG Tech (blog)さんのNotepad++をMayaのスクリプトエディタにするプラグイン NppMayaのちょっとしたメモ
-
Ueta CG Tech (blog)さんのNotepad++をMayaのスクリプトエディタにするプラグイン NppMayaのちょっとしたメモ
C:¥Program Files (x86)¥Notepad++¥plugins
直下に
NppMaya.dll 入れて
Mayaでこのpy実行して
適当にNotePad++でpyスクリプト開いて
プラグイン>NppMaya> SendToScript (スクリプトを送信) Ctrl + Enter
でCtrl + Enter は どことかぶってるかってゆううのは
マクロ>ショートカットの変更から
Main menu
単語補完Ctrl + Enter になっちゃってるから
てきとうにCtrl + ALT +Spacebar でいいかなと。
- | whaison | MayaPython | 13:45 | comments(0) | - | pookmark |
- 2016.09.16 Friday
- FBXExportMelEval.py MayaのFBXExportコマンドをpythonから簡単に使う
-
FBXExportMelEval.py MayaのFBXExportコマンドをpythonから簡単に使う 関連 (http://qiita.com/it_ks/items/8d8f18f6fc359efcd726)
ダブルコーテーションがどうとか書式がまあまあ苦労したのでおいておく。
mel
FBXExportApplyConstantKeyReducer -v false;
FBXExportInAscii -v true;
FBXExportEmbeddedTextures -v false;
FBXExportShowUI -v false;
FBXExport -f ($savePath) -s;pymel
import pymel.core as pm #pymel line 70 only use
pm.FBXExport("-f",FullFilePath+"_pymel_mel_FBXExport","-s")python
cmds.FBXExportApplyConstantKeyReducer('-v',True) #FBXのreductionオプション切り替えがうまくいってない。
cmd.FBXExportApplyConstantKeyReducer が機能してないので、
maya.mel.eval("FBXExportApplyConstantKeyReducer -v false")でつまりmelでやるしかないようだ。
cmds.FBXExport("-f",FullFilePath+"_UnKeyReduction","-s") #OK-----------------------------------------------------------------------------------------------------
-----------------------------------------------------------------------------------------------------
参考サイト
MayaのFBXExportコマンド
http://qiita.com/it_ks/items/8d8f18f6fc359efcd726) - | whaison | MayaPython | 22:41 | comments(0) | - | pookmark |
- 2016.08.14 Sunday
- Maya Python package module ,from ,import ,as, toolset reload
-
C:¥Users¥whaison¥Documents¥maya¥2016¥ja_JP¥scripts¥whaison_tool_001
__init__.py はサブフォルダーにパッケージとして=ネームスペースをほるときにいれとくもの。
なんも書いてなくてもMaya起動時にコンパイルして得られたバイトコード__init__.pycがつくられる。tool_one.py テスト用 関数
from_whaison_tool_001_import_whaison_tool_001.py 呼び出しテスト
- | whaison | MayaPython | 03:20 | comments(0) | - | pookmark |