Can I download and install Python modules from PyPi strictly inside a script, without using a shell at all?
I use a non-standard Python environment, Autodesk Maya's Python interpreter. This does not come with "easy_install," and there is no "shell," only a python script interpreter invoked by the main Maya executable. Copying and pasting ez_setup.py's contents into the script editor window and running it correctly installs an easy_install somewhere into Maya's directory, but the script incorrectly records the Python interpreter as "...maya.exe" instead of "...mayapy.exe" Furthermore, using easy_install requires a shell.
The objective is to deliver a Python script that, e.g., installs NumPy into the Maya Python system. This could be accomplished by dropping eggs into the site-packages directory, but that requires manual user intervention. Anything an end user has to do outside the Maya environment is essentially untouchable, especially messing with the file system. But messing with the filesystem through a script? That's fine.
Is there something more elegant than ez_setup.py + editing the resulting easy_install...py's + subprocess calls? I feel like this is a basic feature. I see documentation online for programmatic module installation through pip... but pip needs to be installed first!
What is the most elegant way to install a module strictly within the confines of a script?
You can use pipreqs to automatically generate a requirements. txt file based on the import statements that the Python script(s) contain. To use pipreqs , assuming that you are in the directory where example.py is located: pip install pipreqs pipreqs .
Use of a Python script to run pip to install a package is not supported by the Python Packaging Authority (PyPA) for the following reason: Pip is not thread-safe, and is intended to be run as a single process. When run as a thread from within a Python script, pip may affect non-pip code with unexpected results.
Installing easy_install for Maya on windows.
Now easy install should be set up properly. You may want to still do following steps:
Now you can call maeasy_install pythonModule from cmd for installing stuff. Also you can call following inside Maya to install modules:
from setuptools.command import easy_install easy_install.main( ["pythonModule"] )
NOTE: If Maya is installed in program files then you can not really install stuff without elevating. Unless you change disk permissions to the Maya python directory.
#!/usr/bin/env python from __future__ import print_function REQUIREMENTS = [ 'distribute', 'version', 'Cython', 'sortedcollection' ] try: from setuptools import find_packages from distutils.core import setup from Cython.Distutils import build_ext as cython_build import sortedcollection except: import os, pip pip_args = [ '-vvv' ] proxy = os.environ['http_proxy'] if proxy: pip_args.append('--proxy') pip_args.append(proxy) pip_args.append('install') for req in REQUIREMENTS: pip_args.append( req ) print('Installing requirements: ' + str(REQUIREMENTS)) pip.main(initial_args = pip_args) # do it again from setuptools import find_packages from distutils.core import setup from Cython.Distutils import build_ext as cython_build import sortedcollection
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With