2017-08-30 112 views
0

我試圖在virtualenv中安裝IPython。我將Virtualenv設置爲使用Pypy 2.7而不是CPython 3.如何在Ubuntu的Pypy virtualenv上安裝iPython 17.04

當我使用由apt-get安裝的IPython時,它最終使用CPython 3代替Pypy。

當我嘗試pip install ipython時,出現編譯錯誤,因爲它找不到Python.h頭文件。這個錯誤在這裏詳述:https://askubuntu.com/questions/922302/install-ipython-with-pip-on-ubuntu-16-04。建議的修復導致錯誤:

Can not perform a '--user' install. User site-packages are not visible in this virtualenv.

[編輯]

完整的錯誤:

Collecting ipython 
    Using cached ipython-5.4.1-py2-none-any.whl 
Requirement already satisfied: decorator in ./site-packages (from ipython) 
Collecting pickleshare (from ipython) 
    Using cached pickleshare-0.7.4-py2.py3-none-any.whl 
Collecting prompt-toolkit<2.0.0,>=1.0.4 (from ipython) 
    Using cached prompt_toolkit-1.0.15-py2-none-any.whl 
Collecting pygments (from ipython) 
    Using cached Pygments-2.2.0-py2.py3-none-any.whl 
Requirement already satisfied: setuptools>=18.5 in ./site-packages (from ipython) 
Collecting simplegeneric>0.8 (from ipython) 
Collecting traitlets>=4.2 (from ipython) 
    Using cached traitlets-4.3.2-py2.py3-none-any.whl 
Collecting backports.shutil-get-terminal-size; python_version == "2.7" (from ipython) 
    Using cached backports.shutil_get_terminal_size-1.0.0-py2.py3-none-any.whl 
Collecting pathlib2; python_version == "2.7" or python_version == "3.3" (from ipython) 
    Using cached pathlib2-2.3.0-py2.py3-none-any.whl 
Collecting pexpect; sys_platform != "win32" (from ipython) 
    Using cached pexpect-4.2.1-py2.py3-none-any.whl 
Requirement already satisfied: six>=1.9.0 in ./site-packages (from prompt-toolkit<2.0.0,>=1.0.4->ipython) 
Collecting wcwidth (from prompt-toolkit<2.0.0,>=1.0.4->ipython) 
    Using cached wcwidth-0.1.7-py2.py3-none-any.whl 
Collecting ipython-genutils (from traitlets>=4.2->ipython) 
    Using cached ipython_genutils-0.2.0-py2.py3-none-any.whl 
Requirement already satisfied: enum34; python_version == "2.7" in ./site-packages (from traitlets>=4.2->ipython) 
Collecting scandir; python_version < "3.5" (from pathlib2; python_version == "2.7" or python_version == "3.3"->ipython) 
    Using cached scandir-1.5.tar.gz 
Collecting ptyprocess>=0.5 (from pexpect; sys_platform != "win32"->ipython) 
    Using cached ptyprocess-0.5.2-py2.py3-none-any.whl 
Building wheels for collected packages: scandir 
    Running setup.py bdist_wheel for scandir ... error 
    Complete output from command /home/me/Documents/pypy-ipython-venv/bin/pypy -u -c "import setuptools, tokenize;__file__='/tmp/pip-build-FmKqsi/scandir/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" bdist_wheel -d /tmp/tmpseW7pdpip-wheel- --python-tag pp256: 
    running bdist_wheel 
    running build 
    running build_py 
    creating build 
    creating build/lib.linux-x86_64-2.7 
    copying scandir.py -> build/lib.linux-x86_64-2.7 
    running build_ext 
    building '_scandir' extension 
    creating build/temp.linux-x86_64-2.7 
    cc -O2 -fPIC -Wimplicit -I/home/me/Documents/pypy-ipython-venv/include -c _scandir.c -o build/temp.linux-x86_64-2.7/_scandir.o 
    _scandir.c:14:20: fatal error: Python.h: No such file or directory 
    #include <Python.h> 
        ^
    compilation terminated. 
    error: command 'cc' failed with exit status 1 

    ---------------------------------------- 
    Failed building wheel for scandir 
    Running setup.py clean for scandir 
Failed to build scandir 
Installing collected packages: scandir, pathlib2, pickleshare, wcwidth, prompt-toolkit, pygments, simplegeneric, ipython-genutils, traitlets, backports.shutil-get-terminal-size, ptyprocess, pexpect, ipython 
    Running setup.py install for scandir ... error 
    Complete output from command /home/me/Documents/pypy-ipython-venv/bin/pypy -u -c "import setuptools, tokenize;__file__='/tmp/pip-build-FmKqsi/scandir/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record /tmp/pip-RqBbsa-record/install-record.txt --single-version-externally-managed --compile --install-headers /home/me/Documents/pypy-ipython-venv/include/site/python2.7/scandir: 
    running install 
    running build 
    running build_py 
    creating build 
    creating build/lib.linux-x86_64-2.7 
    copying scandir.py -> build/lib.linux-x86_64-2.7 
    running build_ext 
    building '_scandir' extension 
    creating build/temp.linux-x86_64-2.7 
    cc -O2 -fPIC -Wimplicit -I/home/me/Documents/pypy-ipython-venv/include -c _scandir.c -o build/temp.linux-x86_64-2.7/_scandir.o 
    _scandir.c:14:20: fatal error: Python.h: No such file or directory 
    #include <Python.h> 
         ^
    compilation terminated. 
    error: command 'cc' failed with exit status 1 

    ---------------------------------------- 
Command "/home/me/Documents/pypy-ipython-venv/bin/pypy -u -c "import setuptools, tokenize;__file__='/tmp/pip-build-FmKqsi/scandir/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record /tmp/pip-RqBbsa-record/install-record.txt --single-version-externally-managed --compile --install-headers /home/me/Documents/pypy-ipython-venv/include/site/python2.7/scandir" failed with error code 1 in /tmp/pip-build-FmKqsi/scandir/ 
+0

了'Python.h'頭應該是'蟒蛇的一部分如果使用python 3或'pypy-dev'作爲pypy,可以使用-dev'軟件包或'python3-dev'。只需安裝它,它應該工作。 – spectras

+0

@spectras我只是做了以下事情:激活virtualenv;做了'sudo apt安裝python-dev';然後'pip安裝ipython'。得到了關於'Python.h'的同樣的錯誤。 – ogogmad

+0

再次嘗試,但這次安裝了'pypy-dev'。同樣的錯誤。 – ogogmad

回答

3

你需要安裝pypy-dev的之前創建的virtualenv。你可以看到gcc命令正在尋找包含在/ home/me/Documents/pypy-ipython-venv/include中的文件,如果在創建虛擬環境時存在頭文件,我擔心目錄只能被正確填充。你可以通過查看該目錄的內容來證明這一點,它應該有一個Python.h文件。

請注意,您只需要安裝pypy-DEV一次,之後你要善於去儘可能多的virtualenvs爲您選擇創建