python3 安装 turtle 报错:Command "python setup.py egg_info" failed with error code 1


python3安装turtle

sudo pip3 install turtle

出现如下报错:

Collecting turtle
  Using cached https://files.pythonhosted.org/packages/ff/f0/21a42e9e424d24bdd0e509d5ed3c7dfb8f47d962d9c044dba903b0b4a26f/turtle-0.0.2.tar.gz
    Complete output from command python setup.py egg_info:
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "/tmp/pip-install-hpqxw6_s/turtle/setup.py", line 40
        except ValueError, ve:
                         ^
    SyntaxError: invalid syntax

    ----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-install-hpqxw6_s/turtle/

原因:setup.py中第四十行 except ValueError, ve 这是python2下的写法,修改一下就好了

解决:下载turtle源码包到自己python第三方包路径下

cd /usr/local/lib/python3.6/dist-packages
wget https://files.pythonhosted.org/packages/ff/f0/21a42e9e424d24bdd0e509d5ed3c7dfb8f47d962d9c044dba903b0b4a26f/turtle-0.0.2.tar.gz
tar -xzvf
turtle-0.0.2.tar.gz
cd turtle-0.0.2
sudo sed -ie 's/except ValueError, ve:/except(ValueError, ve):/g' setup.py
cd ..
sudo pip3 install -e turtle-0.0.2
之后再import turtle又报错:

sudo apt install python3-tk -y

再import 就没问题了



小tips:如果不知道自己的第三方包在哪个路径下,可以python3 -m site查看一下

或者简单粗暴的pip3 install 一个自己确定已经安装过的库就可以看见了

原文地址:https://www.cnblogs.com/cxl-blog/p/12410682.html