Synology的Python,如何安装Python3模块以及安装Python2.7的位置?

时间:2016-07-01 08:54:18

标签: python linux pip tweepy synology

您能告诉我如何使用我的Synology(DS214play,DSM 6.0.1-7393 Update 1)运行模块来获取Python3吗? 我想要的:在我的Synology上运行Python3中的Tweepy和其他模块。

我被困在哪里:

  1. 如何让PIP3安装Tweepy,如果我尝试获取:Requirement already up-to-date: pip in /usr/lib/python2.7/site-packages

    显然我安装了Python 2.7,但我不知道......

    root@DiskStation:/volume1/@appstore/python3/include# ls
    get-pip.py  python3.4m
    root@DiskStation:/volume1/@appstore/python3/include# python3 get-pip.py
    -ash: python3: command not found
    root@DiskStation:/volume1/@appstore/python3/include# python get-pip.py
    Requirement already up-to-date: pip in /usr/lib/python2.7/site-packages
    
  2. 为了让PIP3正常工作,我需要了解Python2.7的安装位置,甚至可以删除它(如果有必要的话)。

  3. 最好知道哪个Python3软件包最适合使用(默认来自Synology DSM软件包管理器或SynoCommunity Python3软件包)

  4. 因为在使用SSH(使用PuTTY)连接到我的Synology时,我可以在DSM包管理器和相关文件夹中看到Python3。

    但是我没有看到Python2.7的任何软件包(我认为必须在那里)并且当用SSH连接时我找不到任何Python 2.7文件夹甚至很难我提示必须有一个“/ usr / lib /python2.7/site-packages“文件夹某处......

    - > Synology DSM软件包管理器的默认Python3位于py3k文件夹中:

    admin@DiskStation: /volume1/@appstore/py3k/usr/local/bin$
    python3
    

    - > SynoCommunity Python3软件包安装在不同的地方:

    admin@DiskStation: /volume1/@appstore/python3$ ls
    bin  etc  include  install.log  lib  openssl.cnf  share
    admin@DiskStation: /volume1/@appstore/python3/bin$ ls
    2to3      busybox  bzfgrep       bzmore     delgroup          fatattr    infocmp    lzmainfo  pip3      python3.4   reset     start-stop-daemon  tset        virtualenv-3.4  xz
    2to3-3.4  bzcat    bzgrep        captoinfo  deluser           gpg-error  infotocap  mpicalc   pip3.4    python3.4m  shuf      tabs               unlink      wheel           xzcat
    addgroup  bzcmp    bzip2         clear      dumpsexp          hmac256    lzcat      nice      pydoc3    pyvenv      speexdec  tic                unlzma      xmlcatalog      xzdec
    adduser   bzdiff   bzip2recover  c_rehash   easy_install      idle3      lzma       openssl   pydoc3.4  pyvenv-3.4  speexenc  toe                unxz        xmllint
    bunzip2   bzegrep  bzless        curl       easy_install-3.4  idle3.4    lzmadec    pip       python3   renice      sqlite3   tput               virtualenv  xsltproc
    admin@DiskStation:/volume1/@appstore/python3/bin$ python3
    -sh: python3: command not found
    

    我做了什么:

    我使用Synology DSM软件包管理器安装了Python3,然后使用SSH(使用PuTTY)连接到我的Synology并设置PATH并使用PIP安装Tweepy和其他模块。

    我相信它有些像以下命令:(不幸的是,大部分都是在不知道具体含义的情况下复制粘贴...)

    root@DiskStation:~# curl -k https://bootstrap.pypa.io/get-pip.py | python
      % Total % Received % Xferd Average Speed Time Time Time Current
      Dload Upload Total Spent Left Speed
    100 1488k 100 1488k 0 0 1577k 0 --:--:-- --:--:-- --:--:-- 1577k
    Collecting pip
      Using cached pip-8.1.2-py2.py3-none-any.whl
    Collecting setuptools
      Downloading setuptools-23.1.0-py2.py3-none-any.whl (435kB)
      100% |████████████████████████████████| 440kB 551kB/s
    Collecting wheel
      Using cached wheel-0.29.0-py2.py3-none-any.whl
    Installing collected packages: pip, setuptools, wheel
    Successfully installed pip-8.1.2 setuptools-23.1.0 wheel-0.29.0
    

    我能够基于此运行脚本并且非常高兴。直到我得到一些(Unicode)错误,并从错误日志中看到它是在我的Synology上运行的2.7版本的Python。看来这些Unicode问题在Python3中得到了解决(我在我的电脑上也有这个问题),所以我想在Synology上使用Python3。

    确实安装了2.7版本,如果我用SSH连接并输入Python,我得到:

    admin@DiskStation:~$ python
    Python 2.7.11 (default, May 13 2016, 05:16:12)
    [GCC 4.9.3 20150311 (prerelease)] on linux2
    Type "help", "copyright", "credits" or "license" for more information.
    

    这很奇怪,因为我在包管理器中没有在Synology看到任何Python 2.7包,所以我必须通过一些我打算用于PIP的SSH命令安装2.7。

    我安装了Synology的默认Python3包,如果我输入admin@DiskStation:~$ python3 我确实准备好了python3。

    在/ volume1 / @ appstore / py3k /中我看到各种Python和PIP版本,而python3运行良好。然而,没有任何模块并且PIP3不起作用(“未找到命令”),我在所有可能的目录和各种格式中尝试了它,如类似的Q& As所示。 pip3.4 install tweepy, pip3 install tweepy, etc.

    所以现在使用DSM包管理器我已经卸载了Python3并安装了SynoCommunity Python3(如Synology forum here所示),它显示了不同的目录结构。但似乎更糟糕,因为现在我看不到对Python 2.7的引用了(但它仍然运行所以必须在那里)甚至无法启动python3:

    admin@DiskStation:~$ cd /volume1
    admin@DiskStation:/volume1$ cd @appstore
    admin@DiskStation:/volume1/@appstore$ cd python3
    admin@DiskStation:/volume1/@appstore/python3$ ls
    bin  etc  include  install.log  lib  openssl.cnf  share
    admin@DiskStation:/volume1/@appstore/python3$ cd bin
    admin@DiskStation:/volume1/@appstore/python3/bin$ ls
    2to3      bzcmp         bzless     deluser           idle3      lzmainfo  pydoc3      renice             tabs    unxz            xz
    2to3-3.4  bzdiff        bzmore     dumpsexp          idle3.4    mpicalc   pydoc3.4    reset              tic     virtualenv      xzcat
    addgroup  bzegrep       captoinfo  easy_install      infocmp    nice      python3     shuf               toe     virtualenv-3.4  xzdec
    adduser   bzfgrep       clear      easy_install-3.4  infotocap  openssl   python3.4   speexdec           tput    wheel
    bunzip2   bzgrep        c_rehash   fatattr           lzcat      pip       python3.4m  speexenc           tset    xmlcatalog
    busybox   bzip2         curl       gpg-error         lzma       pip3      pyvenv      sqlite3            unlink  xmllint
    bzcat     bzip2recover  delgroup   hmac256           lzmadec    pip3.4     pyvenv-3.4  start-stop-daemon  unlzma  xsltproc
    admin@DiskStation:/volume1/@appstore/python3/bin$ python3
    -sh: python3: command not found
    admin@DiskStation:/volume1/@appstore/python3/bin$ python
    Python 2.7.11 (default, May 13 2016, 05:16:12)
    [GCC 4.9.3 20150311 (prerelease)] on linux2
    Type "help", "copyright", "credits" or "license" for more information.
    >>>
    

    所以我达到了要求提供一些提示,提示和建议的重点。

3 个答案:

答案 0 :(得分:2)

好的,很多回复的答案,我解决了它:

  1. 确认默认情况下在Synology DSM 5.2中安装了Python 2.7.9(在包中心不可见)。

  2. 我能够通过使用以下命令专门唤起Python3的pip模块安装来向Python3添加模块:( thx to this Q&A

    /volume1/@appstore/py3k/usr/local/lib/python3.5/site-packages/pip install tweepy

  3. (在这种情况下安装tweepy模块)

    FYI完整的命令概述:

    admin@DiskStation:/volume1/@appstore/py3k/usr/local/lib/python3.5/site-packages$ sudo -i
    Password:
    root@DiskStation:~# curl -O https://bootstrap.pypa.io/get-pip.py
      % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                     Dload  Upload   Total   Spent    Left  Speed
    100 1488k  100 1488k    0     0  1704k      0 --:--:-- --:--:-- --:--:-- 1703k
    root@DiskStation:~# sudo python3 get-pip.py
    Requirement already up-to-date: pip in /volume1/@appstore/py3k/usr/local/lib/python3.5/site-packages
    root@DiskStation:~# pip install tweepy
    Requirement already satisfied (use --upgrade to upgrade): tweepy in /usr/lib/python2.7/site-packages
    Requirement already satisfied (use --upgrade to upgrade): six>=1.7.3 in /usr/lib/python2.7/site-packages (from tweepy)
    Requirement already satisfied (use --upgrade to upgrade): requests>=2.4.3 in /usr/lib/python2.7/site-packages (from tweepy)
    Requirement already satisfied (use --upgrade to upgrade): requests-oauthlib>=0.4.1 in /usr/lib/python2.7/site-packages (from tweepy)
    Requirement already satisfied (use --upgrade to upgrade): oauthlib>=0.6.2 in /usr/lib/python2.7/site-packages (from requests-oauthlib>=0.4.1->tweepy)
    root@DiskStation:~# python3 ^C
    root@DiskStation:~# python3 /volume1/@appstore/py3k/usr/local/lib/python3.5/site-packages/pip install tweepy
    Collecting tweepy
      Using cached tweepy-3.5.0-py2.py3-none-any.whl
    Collecting requests-oauthlib>=0.4.1 (from tweepy)
      Using cached requests_oauthlib-0.6.1-py2.py3-none-any.whl
    Collecting requests>=2.4.3 (from tweepy)
      Using cached requests-2.10.0-py2.py3-none-any.whl
    Collecting six>=1.7.3 (from tweepy)
      Using cached six-1.10.0-py2.py3-none-any.whl
    Collecting oauthlib>=0.6.2 (from requests-oauthlib>=0.4.1->tweepy)
      Using cached oauthlib-1.1.2.tar.gz
    Building wheels for collected packages: oauthlib
      Running setup.py bdist_wheel for oauthlib ... done
      Stored in directory: /root/.cache/pip/wheels/e6/be/43/e4a2ca8cb9c78fbd9b5b14b96cb7a5cc43f36bc11af5dfac5b
    Successfully built oauthlib
    Installing collected packages: requests, oauthlib, requests-oauthlib, six, tweepy
    Successfully installed oauthlib-1.1.2 requests-2.10.0 requests-oauthlib-0.6.1 six-1.10.0 tweepy-3.5.0
    

    (我再次卸载了SynoCommunity Python3包,现在使用DSM包中心的Python3版本)

答案 1 :(得分:1)

  • (1)从DSM软件包中安装python2.7和python3.5
  • (2)ssh登录和 sudo -i
  • (3)运行python并运行python3,如果下一步都可以。
  • (4)运行pip -V应该返回pip 10.0.1,它适用于python2.7
  • (5)运行pip3 -V返回“找不到命令”,..因为路径不正确。
  • (6)试试 / volume1 / @ appstore / py3k / usr / local / bin / pip3 -V
    如果成功。接下来。现在您可以安装适用于python3的模块了,
    路径取决于您的系统,例如:
    / volume1 / @ appstore / py3k / usr / local / bin / pip3 install numpy 应该可以工作!
  • (7)为方便起见,较短的命令非常有用,因此请继续执行下一步:
    sudo vi .profile ,(或.bashrc用于特定用户登录)
  • (8)在末尾添加别名:
    alias pip3 ='/ volume1 / @ appstore / py3k / usr / local / bin / pip3'
  • (9)源.profile或sudo重新启动
  • (10)test pip3 -V ,应该适用于python3.x
  • 答案 2 :(得分:0)

    我不确定你是否可以完全删除Python 2,但你可以安装Python 3并专门用它来代替Python 2.

    首先,确保安装了Python 3: 通过Web管理登录Synology,在“Package Center”中确保安装了“Python 3”。 (您可以在“套餐中心”内的“开发者工具”下找到它)

    接下来,通过简单地调用python3

    来特别唤起Python 3

    您也可以尝试使用Synology上的locate命令查找Python 2的确切位置。为此,请在Synology上输入以下内容:

    ipkg update
    ipkg install mlocate
    

    这是一个关于如何使用命令的教程:http://www.thegeekstuff.com/2012/03/locate-command-examples/

    祝你好运!

    另外, 如果您在Stack Overflow上没有运气,我也会转到Synology论坛寻求帮助:https://forum.synology.com