Python总结

Jupyter

启动

1
jupyter notebook

ModuleNotFoundError: No module named ‘okex’

在导入本地文件夹的文件时报错如上,可以在import这个模块之前添加以下代码,然后再import

1
2
3
4
module_path = os.path.abspath(os.path.join('..'))
print("module_path=", module_path)
if module_path not in sys.path:
sys.path.append(module_path)

AttributeError: module ‘util.file_util’ has no attribute ‘exists’

如果本地的python代码已经修改,如果不重启(刷新)jupyter会报错如上,刷新一下即可。

Pydoc

本地启动

1
python3 -m pydoc -p 6789

pip install报错

错误信息如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
$ pip3.9 install cytoolz
Looking in indexes: http://mirrors.cloud.aliyuncs.com/pypi/simple/
Collecting cytoolz
Downloading http://mirrors.cloud.aliyuncs.com/pypi/packages/58/67/1c60da8ba831bfefedb64c78b9f6820bdf58972797c95644ee3191daf27a/cytoolz-0.11.0.tar.gz (477 kB)
|████████████████████████████████| 477 kB 2.6 MB/s
Requirement already satisfied: toolz>=0.8.0 in /usr/local/lib/python3.9/site-packages (from cytoolz) (0.11.1)
Using legacy 'setup.py install' for cytoolz, since package 'wheel' is not installed.
Installing collected packages: cytoolz
Running setup.py install for cytoolz ... error
ERROR: Command errored out with exit status 1:
command: /usr/bin/python3.9 -u -c 'import io, os, sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-x0b5qh9y/cytoolz_939a8fed01cc43dc979d68c8072b3af1/setup.py'"'"'; __file__='"'"'/tmp/pip-install-x0b5qh9y/cytoolz_939a8fed01cc43dc979d68c8072b3af1/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-sp17_zhm/install-record.txt --single-version-externally-managed --compile --install-headers /usr/local/include/python3.9/cytoolz
cwd: /tmp/pip-install-x0b5qh9y/cytoolz_939a8fed01cc43dc979d68c8072b3af1/
Complete output (63 lines):
[1/5] Cythonizing cytoolz/dicttoolz.pyx
[2/5] Cythonizing cytoolz/functoolz.pyx
[3/5] Cythonizing cytoolz/itertoolz.pyx
[4/5] Cythonizing cytoolz/recipes.pyx
[5/5] Cythonizing cytoolz/utils.pyx
/usr/local/lib/python3.9/site-packages/setuptools/dist.py:691: UserWarning: Usage of dash-separated 'index-url' will not be supported in future versions. Please use the underscore name 'index_url' instead
warnings.warn(
running install
running build
running build_py
creating build
creating build/lib.linux-x86_64-3.9
creating build/lib.linux-x86_64-3.9/cytoolz
copying cytoolz/__init__.py -> build/lib.linux-x86_64-3.9/cytoolz
copying cytoolz/_signatures.py -> build/lib.linux-x86_64-3.9/cytoolz
copying cytoolz/_version.py -> build/lib.linux-x86_64-3.9/cytoolz
copying cytoolz/compatibility.py -> build/lib.linux-x86_64-3.9/cytoolz
copying cytoolz/utils_test.py -> build/lib.linux-x86_64-3.9/cytoolz
creating build/lib.linux-x86_64-3.9/cytoolz/curried
copying cytoolz/curried/__init__.py -> build/lib.linux-x86_64-3.9/cytoolz/curried
copying cytoolz/curried/exceptions.py -> build/lib.linux-x86_64-3.9/cytoolz/curried
copying cytoolz/curried/operator.py -> build/lib.linux-x86_64-3.9/cytoolz/curried
copying cytoolz/dicttoolz.pyx -> build/lib.linux-x86_64-3.9/cytoolz
copying cytoolz/functoolz.pyx -> build/lib.linux-x86_64-3.9/cytoolz
copying cytoolz/itertoolz.pyx -> build/lib.linux-x86_64-3.9/cytoolz
copying cytoolz/recipes.pyx -> build/lib.linux-x86_64-3.9/cytoolz
copying cytoolz/utils.pyx -> build/lib.linux-x86_64-3.9/cytoolz
copying cytoolz/__init__.pxd -> build/lib.linux-x86_64-3.9/cytoolz
copying cytoolz/cpython.pxd -> build/lib.linux-x86_64-3.9/cytoolz
copying cytoolz/dicttoolz.pxd -> build/lib.linux-x86_64-3.9/cytoolz
copying cytoolz/functoolz.pxd -> build/lib.linux-x86_64-3.9/cytoolz
copying cytoolz/itertoolz.pxd -> build/lib.linux-x86_64-3.9/cytoolz
copying cytoolz/recipes.pxd -> build/lib.linux-x86_64-3.9/cytoolz
copying cytoolz/utils.pxd -> build/lib.linux-x86_64-3.9/cytoolz
creating build/lib.linux-x86_64-3.9/cytoolz/tests
copying cytoolz/tests/dev_skip_test.py -> build/lib.linux-x86_64-3.9/cytoolz/tests
copying cytoolz/tests/test_compatibility.py -> build/lib.linux-x86_64-3.9/cytoolz/tests
copying cytoolz/tests/test_curried.py -> build/lib.linux-x86_64-3.9/cytoolz/tests
copying cytoolz/tests/test_curried_toolzlike.py -> build/lib.linux-x86_64-3.9/cytoolz/tests
copying cytoolz/tests/test_dev_skip_test.py -> build/lib.linux-x86_64-3.9/cytoolz/tests
copying cytoolz/tests/test_dicttoolz.py -> build/lib.linux-x86_64-3.9/cytoolz/tests
copying cytoolz/tests/test_docstrings.py -> build/lib.linux-x86_64-3.9/cytoolz/tests
copying cytoolz/tests/test_doctests.py -> build/lib.linux-x86_64-3.9/cytoolz/tests
copying cytoolz/tests/test_embedded_sigs.py -> build/lib.linux-x86_64-3.9/cytoolz/tests
copying cytoolz/tests/test_functoolz.py -> build/lib.linux-x86_64-3.9/cytoolz/tests
copying cytoolz/tests/test_inspect_args.py -> build/lib.linux-x86_64-3.9/cytoolz/tests
copying cytoolz/tests/test_itertoolz.py -> build/lib.linux-x86_64-3.9/cytoolz/tests
copying cytoolz/tests/test_none_safe.py -> build/lib.linux-x86_64-3.9/cytoolz/tests
copying cytoolz/tests/test_recipes.py -> build/lib.linux-x86_64-3.9/cytoolz/tests
copying cytoolz/tests/test_serialization.py -> build/lib.linux-x86_64-3.9/cytoolz/tests
copying cytoolz/tests/test_signatures.py -> build/lib.linux-x86_64-3.9/cytoolz/tests
copying cytoolz/tests/test_tlz.py -> build/lib.linux-x86_64-3.9/cytoolz/tests
copying cytoolz/tests/test_utils.py -> build/lib.linux-x86_64-3.9/cytoolz/tests
running build_ext
building 'cytoolz.dicttoolz' extension
creating build/temp.linux-x86_64-3.9
creating build/temp.linux-x86_64-3.9/cytoolz
gcc -pthread -Wno-unused-result -Wsign-compare -DDYNAMIC_ANNOTATIONS_ENABLED=1 -DNDEBUG -O2 -g -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -Wp,-D_GLIBCXX_ASSERTIONS -fexceptions -fstack-protector-strong -grecord-gcc-switches -m64 -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection -D_GNU_SOURCE -fPIC -fwrapv -O2 -g -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -Wp,-D_GLIBCXX_ASSERTIONS -fexceptions -fstack-protector-strong -grecord-gcc-switches -m64 -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection -D_GNU_SOURCE -fPIC -fwrapv -O2 -g -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -Wp,-D_GLIBCXX_ASSERTIONS -fexceptions -fstack-protector-strong -grecord-gcc-switches -m64 -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection -D_GNU_SOURCE -fPIC -fwrapv -fPIC -I/usr/include/python3.9 -c cytoolz/dicttoolz.c -o build/temp.linux-x86_64-3.9/cytoolz/dicttoolz.o
cytoolz/dicttoolz.c:19:10: fatal error: Python.h: No such file or directory
#include "Python.h"
^~~~~~~~~~
compilation terminated.
error: command '/usr/bin/gcc' failed with exit code 1
----------------------------------------
ERROR: Command errored out with exit status 1: /usr/bin/python3.9 -u -c 'import io, os, sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-x0b5qh9y/cytoolz_939a8fed01cc43dc979d68c8072b3af1/setup.py'"'"'; __file__='"'"'/tmp/pip-install-x0b5qh9y/cytoolz_939a8fed01cc43dc979d68c8072b3af1/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-sp17_zhm/install-record.txt --single-version-externally-managed --compile --install-headers /usr/local/include/python3.9/cytoolz Check the logs for full command output.

解决方法:

1
sudo yum install python39-devel