2017-09-09 55 views
0

我分叉了一個Github repo,並且正在努力編譯該項目。我使用Ubuntu的,我試圖使用setup.py文件安裝,但我得到這個:Python 3找不到setuptools模塊 - Ubuntu

$sudo apt-get install python3-setuptools 
    Reading package lists... Done 
    Building dependency tree 
    Reading state information... Done 
    python3-setuptools is already the newest version (20.7.0-1) 
    0 upgraded, 0 newly installed, 0 to remove, and 100 not upgraded. 
$python3 setup.py install 
    Traceback (most recent call last): 
    File "setup.py", line 5, in <module> 
     from setuptools import setup, find_packages 
    ModuleNotFoundError: No module named 'setuptools' 

我也試着使用Python 2編譯我以前sudo apt-get install python-setuptools,然後當我嘗試python setup.py install我得到的一個問題我認爲這意味着我正在編譯的代碼是python 3代碼。問題是

File "/usr/local/lib/python2.7/dist-packages/pokemon_terminal-0.0.1-py2.7.egg/pokemonterminal/database.py", line 101 
def get_pokemon_of_type(self, pkmn_type: str, single: bool = True): 
            ^
SyntaxError: invalid syntax 

我在Ubuntu終端上運行這個。我想知道是否有人對我的情況有所瞭解。謝謝!

回答

0

嘗試直接從代碼本身安裝模塊。

try: 
    import setuptools 
except: 
    import os 
    os.system("pip install setuptools") 
    del os 
+0

看起來它仍然不能使用setuptools:它安裝了setuptools,但是卻找不到setup()方法,我假設它是在setuptools中 ' –

1

虛擬環境可能會解決這個問題。

sudo pip install virtualenv 
virtualenv -p python3 myenv 
source myenv/bin/activate 
... do whatever you need to do. 
0

我結束了重新編譯我的Python 3,它安裝了最新版本的pip和setuptools並工作。問題解決了!