0

I'm keeping a project on a microSD card, because I want to be able to transfer it between devices. As a result, I have all libraries located on the microSD.

I want to install all the libraries from the microSD, rather than their repositories, so I have the same version between each device. Thus, I want the program to auto-install these libraries when I run it for the first time on a machine.

I have this chunk of code here to take care of that:

import os
import sys

#Get the project base directory (drive located on)
def get_project_base_directory():
    global basedir
    cwd = os.getcwd()
    basedir = "/".join(cwd.split("\\")[:len(cwd.split("\\"))-1])
    print basedir


#Install libraries if they don't exist on this machine.
def install_libs():
    libs_list = ("fbchat", "gTTS", "PyAudio", "pygooglevoice", "espeak", "pywapi", "speech_recognition") #names of libs
    libs_file_list = ("/Libraries/Installed/fbchat-1.0.19/setup.py", "/Libraries/Installed/gTTS-1.2.2/setup.py", "/Libraries/Installed/PyAudio-0.2.11/setup.py", "/Libraries/Installed/pygooglevoice-master/setup.py", "/Libraries/Installed/python-espeak-0.5/setup.py", "/Libraries/Installed/pywapi-0.3.8/setup.py", "/Libraries/Installed/speech_recognition-master/setup.py") #lib location, without drive name
    for lib in libs_list:
        var = lib in sys.modules
        if var == False:
            print "Installing:", lib
            lib_file = basedir + libs_file_list[libs_list.index(lib)] #Temporarily adds drive name during install process
            try:
                os.system("python " + lib_file + " install")
            except:
                print lib, "failed installation. Try manual install."

All get flagged as not having been installed on this machine (which is true). HOWEVER, they all return an error when trying to install (which the "except" is not handling).

Here's what they return:

Installing: fbchat
Traceback (most recent call last):
  File "E:/Libraries/Installed/fbchat-1.0.19/setup.py", line 16, in <module>
    with open('README.rst') as f:
IOError: [Errno 2] No such file or directory: 'README.rst'
Installing: gTTS
Traceback (most recent call last):
  File "E:/Libraries/Installed/gTTS-1.2.2/setup.py", line 6, in <module>
    exec(open('gtts/version.py').read())
IOError: [Errno 2] No such file or directory: 'gtts/version.py'
Installing: PyAudio
running install
error: error in 'egg_base' option: 'src' does not exist or is not a directory
running bdist_egg
Installing: pygooglevoice
running install
running build
running build_py
error: package directory 'googlevoice' does not exist
Installing: espeak
running install
running build
running build_py
error: package directory 'espeak' does not exist
Installing: pywapi
running install
running build
running build_py
file pywapi.py (for module pywapi) not found
file pywapi.py (for module pywapi) not found
warning: install_lib: 'build\lib' does not exist -- no Python modules to install

running install_lib
running install_egg_info
Removing C:\python27\Lib\site-packages\pywapi-0.3.8-py2.7.egg-info
Writing C:\python27\Lib\site-packages\pywapi-0.3.8-py2.7.egg-info
Installing: speech_recognition
Traceback (most recent call last):
  File "E:/Libraries/Installed/speech_recognition-master/setup.py", line 50, in <module>
long_description=open("README.rst").read(),
IOError: [Errno 2] No such file or directory: 'README.rst'

BUT README.rst does exist (I checked, and so do all the other "non-existent" files). Why might this be happening? How can I fix this, other than going in and manually installing each lib (this would be a pain in the ass if I get 10+ libraries).

I'm also curious on how to do version control. i.e., if an older version exists on this device, how do I overwrite it with my new version, without installing the lib every time I'm on this machine?

EDIT 1: Even if I do this manually (through CMD), I still get hung up on README.rst not existing... any ideas?

TobyTobyo
  • 405
  • 2
  • 6
  • 20
  • why not use a virtualenv, located on the sd? – jeremycg Sep 07 '17 at 18:30
  • @jeremycg because this is going to be downloaded onto several machines once the project is finished. It's a basic "Alexa"-like program that I'm coding for myself, my parents, and my dorm-mates, since us college students are too cheap to buy an echo. Plus, I want a challenge, and to say its truly my own. – TobyTobyo Sep 07 '17 at 18:34
  • Check path of invocation against README.rst file. Probably, you can log currently working directory and directory from setup.py. That should help you debug. – cprakashagr Sep 07 '17 at 20:15
  • @cprakashagr how do I do that? I've found this [link](https://stackoverflow.com/questions/5466329/whats-the-best-way-to-determine-the-location-of-the-current-powershell-script), but I don't have powershell. Is there a way you know of to do that in python? – TobyTobyo Sep 07 '17 at 21:21

0 Answers0