我想从mayas python解释器中下载并安装setup_tools,easy_install和tinydb ..
在下面的代码中查看setup()。
我非常接近,但看起来运行ez-setup.py的系统命令并没有将easy_install软件包下载到mayas site_packages目录,这很奇怪,因为同样的命令在shell中完美运行。
所以系统调用如下所示: /Applications/Autodesk/maya2016/Maya.app/Contents/bin/mayapy /Users/paxtongerrish/downloads/ez_setup.py
我指的是ez_setup.py
中的mayas python解释器当我将此命令打入shell时,它会将setup_tools下载到mayas python site_packages目录中......太棒了! :d
然而..我需要从mayas python解释器内部发生这一切,并且当从os.system或subprocess.call调用时它不起作用
谢谢! 进口口 导入系统 import urllib2 导入子流程
setup_tools_address = 'https://bitbucket.org/pypa/setuptools/raw/bootstrap/ez_setup.py'
downloads_directory = '%s/downloads' % os.getenv('HOME')
if not os.path.exists(downloads_directory):
os.makedirs(downloads_directory)
def setup():
url = setup_tools_address
file_path = '%s/%s' % (downloads_directory, url.split('/')[-1])
maya_py = maya_py_path()
for p in download_url(url, file_path):
print p
system_command = '%s %s' % (maya_py, file_path)
print '----- sys command--- (only works in shell)------\n'
print system_command
print '\n----------------------------------------------\n'
#This system command works from shell, but not from python.... Maybe superuser thing??
#os.system(system_command)
#sub process doesnt work either
p = subprocess.Popen([maya_py, file_path], shell=True, stdout=subprocess.PIPE)
print '--->>'
p.wait()
for i in p.stdout.readline():
sys.stdout.flush()
print i
add_eggs()
from setuptools.command import easy_install
easy_install.main(['tinydb'])
add_eggs()
import tinydb
def download_url(url, file_path, block_size=2056):
request = urllib2.urlopen(url)
file_size = int(request.info()['Content-Length'])
if not file_path:
file_path = '%s/%s' % (os.getenv('HOME'), url.split("/")[-1])
downloaded_chunk = 0
with open(file_path, "wb") as f:
while downloaded_chunk < file_size:
chunk = request.read(block_size)
downloaded_chunk += len(chunk)
f.write(chunk)
progress = float(downloaded_chunk) / file_size * 100
yield progress
print("\nDownload Complete.")
def maya_app_path():
appName = 'Maya'
if sys.platform == 'win32':
appName = 'Maya.exe'
for p in sys.path:
app_path = '%s/%s' % (p.replace('\\','/') , appName)
if os.path.exists(app_path):
return app_path
def maya_py_path():
file_name = 'mayapy'
if sys.platform == 'win32':
file_name = 'mayapy.exe'
return '%s\\%s' % (os.path.dirname(maya_app_path().replace('/','\\')), file_name.replace('/','\\'))
return '%s/bin/%s' % (os.path.dirname(os.path.dirname(maya_app_path())), file_name)
def get_site_packages_directory():
for p in sys.path:
if p.endswith('site-packages'):
return p
def add_eggs():
site_packages_directory = get_site_packages_directory()
for item in os.listdir(site_packages_directory):
if item.endswith('.egg'):
sys.path.append('%s/%s' % (site_packages_directory, item))