尝试使用python安装python模块

时间:2017-09-07 18:29:02

标签: python python-2.7 automation libraries

我在microSD卡上保留了一个项目,因为我希望能够在设备之间传输它。因此,我将所有库都放在microSD上。

我想安装microSD中的所有库,而不是他们的存储库,所以我在每个设备之间都有相同的版本。因此,我希望程序在我第一次在计算机上运行时自动安装这些库。

我在这里有一大堆代码可以解决这个问题:

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."

所有标记为未在此计算机上安装(这是真的)。但是,它们在尝试安装时都会返回错误(“处理”除外)。

这是他们的回报:

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'

但README.rst确实存在(我检查过,所有其他“不存在的”文件也是如此)。为什么会发生这种情况?我怎么能解决这个问题,除了进入并手动安装每个lib(如果我有10个以上的库,这将是一个痛苦的事。)

我也很好奇如何进行版本控制。即,如果此设备上存在旧版本,如何使用我的新版本覆盖它,而不是每次都在我的机器上安装lib?

编辑1:即使我手动执行此操作(通过CMD),我仍然会挂起README.rst不存在...任何想法?

0 个答案:

没有答案