文章目录


setup.py与pip的比较

pip与setup.py的比较_python


下面是一次排错的过程可以不看

安装库时遇到的问题

在安装库的时候遇到提示:

$ pip install lws
Collecting lws
Using cached lws-1.2.7.tar.gz (150 kB)
Preparing metadata (setup.py) ... done
Requirement already satisfied: numpy in /home/lwz/anaconda3/lib/python3.6/site-packages (from lws) (1.19.5)
Building wheels for collected packages: lws
Building wheel for lws (setup.py) ... error
ERROR: Command errored out with exit status 1:
command: /home/lwz/anaconda3/bin/python -u -c 'import io, os, sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-qyk5mibx/lws_19e00b2304c54c2e87245aa99e8f495a/setup.py'"'"'; __file__='"'"'/tmp/pip-install-qyk5mibx/lws_19e00b2304c54c2e87245aa99e8f495a/setup.py'"'"';f = getattr(tokenize, '"'"'open'"'"', open)(__file__) if os.path.exists(__file__) else io.StringIO('"'"'from setuptools import setup; setup()'"'"');code = f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' bdist_wheel -d /tmp/pip-wheel-01pkjc_r
cwd: /tmp/pip-install-qyk5mibx/lws_19e00b2304c54c2e87245aa99e8f495a/
Complete output (10 lines):
running bdist_wheel
running build
running build_ext
building 'lws' extension
creating build
creating build/temp.linux-x86_64-3.6
creating build/temp.linux-x86_64-3.6/lwslib
gcc -pthread -B /home/lwz/anaconda3/compiler_compat -Wl,--sysroot=/ -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -fPIC -Ilwslib/ -I/home/lwz/anaconda3/lib/python3.6/site-packages/numpy/core/include -I/home/lwz/anaconda3/include/python3.6m -c lws.bycython.cpp -o build/temp.linux-x86_64-3.6/lws.bycython.o -O3
unable to execute 'gcc': No such file or directory
error: command 'gcc' failed with exit status 1
----------------------------------------
ERROR: Failed building wheel for lws
Running setup.py clean for lws
Failed to build lws
Installing collected packages: lws
Running setup.py install for lws ... error
ERROR: Command errored out with exit status 1:
command: /home/lwz/anaconda3/bin/python -u -c 'import io, os, sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-qyk5mibx/lws_19e00b2304c54c2e87245aa99e8f495a/setup.py'"'"'; __file__='"'"'/tmp/pip-install-qyk5mibx/lws_19e00b2304c54c2e87245aa99e8f495a/setup.py'"'"';f = getattr(tokenize, '"'"'open'"'"', open)(__file__) if os.path.exists(__file__) else io.StringIO('"'"'from setuptools import setup; setup()'"'"');code = f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record /tmp/pip-record-9onhrnq4/install-record.txt --single-version-externally-managed --compile --install-headers /home/lwz/anaconda3/include/python3.6m/lws
cwd: /tmp/pip-install-qyk5mibx/lws_19e00b2304c54c2e87245aa99e8f495a/
Complete output (12 lines):
running install
/home/lwz/anaconda3/lib/python3.6/site-packages/setuptools/command/install.py:37: SetuptoolsDeprecationWarning: setup.py install is deprecated. Use build and pip and other standards-based tools.
setuptools.SetuptoolsDeprecationWarning,
running build
running build_ext
building 'lws' extension
creating build
creating build/temp.linux-x86_64-3.6
creating build/temp.linux-x86_64-3.6/lwslib
gcc -pthread -B /home/lwz/anaconda3/compiler_compat -Wl,--sysroot=/ -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -fPIC -Ilwslib/ -I/home/lwz/anaconda3/lib/python3.6/site-packages/numpy/core/include -I/home/lwz/anaconda3/include/python3.6m -c lws.bycython.cpp -o build/temp.linux-x86_64-3.6/lws.bycython.o -O3
unable to execute 'gcc': No such file or directory
error: command 'gcc' failed with exit status 1
----------------------------------------
ERROR: Command errored out with exit status 1: /home/lwz/anaconda3/bin/python -u -c 'import io, os, sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-qyk5mibx/lws_19e00b2304c54c2e87245aa99e8f495a/setup.py'"'"'; __file__='"'"'/tmp/pip-install-qyk5mibx/lws_19e00b2304c54c2e87245aa99e8f495a/setup.py'"'"';f = getattr(tokenize, '"'"'open'"'"', open)(__file__) if os.path.exists(__file__) else io.StringIO('"'"'from setuptools import setup; setup()'"'"');code = f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record /tmp/pip-record-9onhrnq4/install-record.txt --single-version-externally-managed --compile --install-headers /home/lwz/anaconda3/include/python3.6m/lws Check the logs for full command output.

一开始没细看,按照提示认为是build wheels步骤出错,于是查资料总结成了上面​​pip与setup.py​​的比较图表

后来仔细看发现是因为​​wsl2不默认装gcc​​,于是装一个gcc就完事了

sudo apt install build-essential

总之23333

参考文献