尝试在虚拟环境中安装软件包时出现 AttributeError: install_layout

问题描述 投票:0回答:6

我正在尝试在我的 Ubuntu 15.10 PC 上设置虚拟环境。从我的主目录中,我运行了以下命令:

virtualenv python
source python/bin/activate
pip install ujson

以下是

~/.pip/pip.log
的(下半部分)内容:

running build                                                                    
running build_ext                                                                
building 'ujson' extension                                                       
creating build                                                                   
creating build/temp.linux-x86_64-2.7                                             
creating build/temp.linux-x86_64-2.7/python                                      
creating build/temp.linux-x86_64-2.7/lib                                         
distcc clang-3.7 -fno-strict-aliasing -g -O2 -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -fPIC -I./python -I./lib -I/usr/include/python2.7 -c ./python/ujson.c -o build/temp.linux-x86_64-2.7/./python/ujson.o -D_GNU_SOURCE
distcc clang-3.7 -fno-strict-aliasing -g -O2 -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -fPIC -I./python -I./lib -I/usr/include/python2.7 -c ./python/objToJSON.c -o build/temp.linux-x86_64-2.7/./python/objToJSON.o -D_GNU_SOURCE
distcc clang-3.7 -fno-strict-aliasing -g -O2 -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -fPIC -I./python -I./lib -I/usr/include/python2.7 -c ./python/JSONtoObj.c -o build/temp.linux-x86_64-2.7/./python/JSONtoObj.o -D_GNU_SOURCE
distcc clang-3.7 -fno-strict-aliasing -g -O2 -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -fPIC -I./python -I./lib -I/usr/include/python2.7 -c ./lib/ultrajsonenc.c -o build/temp.linux-x86_64-2.7/./lib/ultrajsonenc.o -D_GNU_SOURCE
distcc clang-3.7 -fno-strict-aliasing -g -O2 -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -fPIC -I./python -I./lib -I/usr/include/python2.7 -c ./lib/ultrajsondec.c -o build/temp.linux-x86_64-2.7/./lib/ultrajsondec.o -D_GNU_SOURCE
creating build/lib.linux-x86_64-2.7                                              
gcc -pthread -shared build/temp.linux-x86_64-2.7/./python/ujson.o build/temp.linux-x86_64-2.7/./python/objToJSON.o build/temp.linux-x86_64-2.7/./python/JSONtoObj.o build/temp.linux-x86_64-2.7/./lib/ultrajsonenc.o build/temp.linux-x86_64-2.7/./lib/ultrajsondec.o -L/usr/lib -lpython2.7 -o build/lib.linux-x86_64-2.7/ujson.so
running install_lib                                                              
Traceback (most recent call last):                                               
  File "<string>", line 1, in <module>                                           
  File "/tmp/pip-build-v2tojT/ujson/setup.py", line 69, in <module>              
    classifiers=CLASSIFIERS,                                                     
  File "/usr/lib/python2.7/distutils/core.py", line 151, in setup                
    dist.run_commands()                                                          
  File "/usr/lib/python2.7/distutils/dist.py", line 953, in run_commands         
    self.run_command(cmd)                                                        
  File "/usr/lib/python2.7/distutils/dist.py", line 972, in run_command          
    cmd_obj.run()                                                                
  File "/home/quant/python/lib/python2.7/site-packages/setuptools/command/install.py", line 61, in run
    return orig.install.run(self)                                                
  File "/usr/lib/python2.7/distutils/command/install.py", line 575, in run       
    self.run_command(cmd_name)                                                   
  File "/usr/lib/python2.7/distutils/cmd.py", line 326, in run_command           
    self.distribution.run_command(command)                                       
  File "/usr/lib/python2.7/distutils/dist.py", line 971, in run_command          
    cmd_obj.ensure_finalized()                                                   
  File "/usr/lib/python2.7/distutils/cmd.py", line 109, in ensure_finalized      
    self.finalize_options()                                                      
  File "/home/quant/python/lib/python2.7/site-packages/setuptools/command/install_lib.py", line 17, in finalize_options
    self.set_undefined_options('install',('install_layout','install_layout'))    
  File "/usr/lib/python2.7/distutils/cmd.py", line 302, in set_undefined_options 
    getattr(src_cmd_obj, src_option))                                            
  File "/usr/lib/python2.7/distutils/cmd.py", line 105, in __getattr__           
    raise AttributeError, attr                                                   
AttributeError: install_layout                                                   
----------------------------------------                                         
Cleaning up...                                                                   
Command /home/quant/python/bin/python2 -c "import setuptools, tokenize;__file__='/tmp/pip-build-v2tojT/ujson/setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record /tmp/pip-rkdmJT-record/install-record.txt --single-version-externally-managed --compile --install-headers /home/quant/python/include/site/python2.7 failed with error code 1 in /tmp/pip-build-v2tojT/ujson
Exception information:                                                           
Traceback (most recent call last):                                               
  File "/home/quant/python/lib/python2.7/site-packages/pip/basecommand.py", line 122, in main
    status = self.run(options, args)                                             
  File "/home/quant/python/lib/python2.7/site-packages/pip/commands/install.py", line 309, in run
    requirement_set.install(install_options, global_options, root=options.root_path)
  File "/home/quant/python/lib/python2.7/site-packages/pip/req.py", line 1436, in install
    requirement.install(install_options, global_options, *args, **kwargs)        
  File "/home/quant/python/lib/python2.7/site-packages/pip/req.py", line 707, in install
    cwd=self.source_dir, filter_stdout=self._filter_install, show_stdout=False)  
  File "/home/quant/python/lib/python2.7/site-packages/pip/util.py", line 716, in call_subprocess
    % (command_desc, proc.returncode, cwd))                                      
InstallationError: Command /home/quant/python/bin/python2 -c "import setuptools, tokenize;__file__='/tmp/pip-build-v2tojT/ujson/setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record /tmp/pip-rkdmJT-record/install-record.txt --single-version-externally-managed --compile --install-headers /home/quant/python/include/site/python2.7 failed with error code 1 in /tmp/pip-build-v2tojT/ujson

一些可能有用的信息:

(python)quant@OptiPlex-990:~$ pip --version
pip 1.5.6 from /home/quant/python/lib/python2.7/site-packages (python 2.7)
(python)quant@OptiPlex-990:~$ which python
/home/quant/python/bin/python
(python)quant@OptiPlex-990:~$ python --version
Python 2.7.10

我尝试安装其他软件包(例如

numpy
),结果类似;编译完成,但是当它尝试运行时它会爆炸
install_lib

python python-2.7 virtualenv
6个回答
126
投票

您尝试过更新安装工具吗?

pip install -U setuptools

然后:

pip install ujson


27
投票

这可能是“setuptools”过时的问题。

pip install --升级安装工具

应该可以解决问题。


12
投票

升级到 Ubuntu 22.04 后,我对其他软件包也遇到了非常类似的问题,它显然来自 setuptools。接下来:pypa/setuptools#3278

我尝试在终端中运行:

export SETUPTOOLS_USE_DISTUTILS=stdlib
,它的效果非常好!


9
投票

我的

setuptools
是最新的,所以我必须强制重新安装它,然后它就可以工作了。

pip install --upgrade --force-reinstall setuptools


0
投票

对于我来说

pip install --升级 pip setuptools 轮

成功了


-8
投票

我更新到 Ubuntu 16.04,在破坏我的 virtualenv 并从头开始之后,没有再看到这个问题。

© www.soinside.com 2019 - 2024. All rights reserved.