文章目录
1 新建一个用于人工智能环境的虚拟环境
mkvirtualenv -p /user/local/bin/python3 ai
错误信息⚠️
command not found: mkvirtualenv
1.1 检查pip
1.1.1 第一步检查
~~~
sudo pip install virtualenv
错误信息⚠️
WARNING: You are using pip version 20.3.3; however, version 21.0 is available.
You should consider upgrading via the '/Users/shenfan/opt/anaconda3/bin/python -m pip install --upgrade pip' command.
这个错误信息出现的原因是因为pip版本过低导致的第三方库安装失败
输入python -m pip install --upgrade pip
1.1.2 更新pip
python -m pip install --upgrade pip
然后这里还好啦,但是下载到一半的时候就会出问题了。
错误信息⚠️
网上有方法说是修改pip __main__方法,但是不行
后来查到了网上有种说法是pip不支持断点续传,那么换国内镜像下载吧,也不行
最后还是想到是不是权限问题哦,果然可以成功更新啦~
python -m pip install -U --force-reinstall pip
1.1.3 第二步检查
sudo pip install virtualenv
警告信息⚠️
WARNING: The directory '/Users/shenfan/Library/Caches/pip' or its parent directory is not owned or is not writable by the current user. The cache has been disabled. Check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
这个提示就很明显啦。以后执行pip操作的时候加上-H即可,but,每次加上这个还挺麻烦的
sudo -H pip install xxxx
1.1.4 写入权限
因此,先把这个解决一下下吧
提示是说咱们没有写入权限,那么加上权限即可啦
我的是
sudo chown -R shenfan /Users/shenfan/Library/Caches/pip
你要改成自己的用户名啊,路径改成警告里面出现的pip路径即可。
sudo chown -R YourUserName /Users/YourUserName/Library/Caches/pip
sudo pip install virtualenvwrapper
这下可算是没问题了,如果是说还报上个错误,可以妥协一下下
sudo -H pip install virtualenvwrapper
1.2 修改.bashrc
sudo pip install virtualenvwrapper
1.2.1 找路径
which virtualenvwrapper.sh
加上
export WORKON_HOME=~/.environments
source + virtualenvwrapper.sh路径
1.2.2 加载使配置文件生效
source ~/.bashrc
继续~
mkvirtualenv -p /user/local/bin/python3 ai
然后发现了
错误信息⚠️
No such file or directory: '/user/local/bin/python3'
我相信这是最后一个问题了
乖乖的查询一下路径吧
echo $PATH
/Users/shenfan/peizhi/apache-maven-3.6.3/bin:/Library/Java/JavaVirtualMachines/jdk-13.0.1.jdk/Contents/Home/bin:/Users/shenfan/opt/anaconda3/bin:/Users/shenfan/opt/anaconda3/condabin:/Users/shenfan/peizhi/apache-maven-3.6.3/bin:/Library/Java/JavaVirtualMachines/jdk-13.0.1.jdk/Contents/Home/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Library/Apple/usr/bin:.:/Users/shenfan/.rvm/bin:/usr/local/mysql/bin::/usr/local/mysql/bin:/Users/shenfan/.rvm/bin:/Users/shenfan/.rvm/bin
which python
/Users/shenfan/opt/anaconda3/bin/python
mkvirtualenv -p /Users/shenfan/opt/anaconda3/bin/python ai
接下来
2 使用pip命令安装库
2.1 新建一个requirements.txt文件
(使用稳定版本安装)
matplotlib==2.2.2
numpy==1.14.2
pandas==0.20.3
tables==3.4.2
Jupyter==1.0.0
ls到当前文件目录下,输入命令
pip install -r requirements.txt
下着下着又出问题了
错误信息⚠️
ERROR: Command errored out with exit status 1:
command: /Users/shenfan/.environments/ai/bin/python -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/private/var/folders/v9/0t1fh7kd28b57xdgr82x720w0000gn/T/pip-install-z9d5pfnf/tables_3a5a0a5e4f554b1782ffd796e7063bcd/setup.py'"'"'; __file__='"'"'/private/var/folders/v9/0t1fh7kd28b57xdgr82x720w0000gn/T/pip-install-z9d5pfnf/tables_3a5a0a5e4f554b1782ffd796e7063bcd/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' egg_info --egg-base /private/var/folders/v9/0t1fh7kd28b57xdgr82x720w0000gn/T/pip-pip-egg-info-nvwe9e8_
cwd: /private/var/folders/v9/0t1fh7kd28b57xdgr82x720w0000gn/T/pip-install-z9d5pfnf/tables_3a5a0a5e4f554b1782ffd796e7063bcd/
Complete output (10 lines):
* Using Python 3.7.6 (default, Jan 8 2020, 13:42:34)
* USE_PKGCONFIG: True
* Found conda env: ``/Users/shenfan/opt/anaconda3``
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/private/var/folders/v9/0t1fh7kd28b57xdgr82x720w0000gn/T/pip-install-z9d5pfnf/tables_3a5a0a5e4f554b1782ffd796e7063bcd/setup.py", line 597, in <module>
hdf5_version = get_hdf5_version(hdf5_header)
File "/private/var/folders/v9/0t1fh7kd28b57xdgr82x720w0000gn/T/pip-install-z9d5pfnf/tables_3a5a0a5e4f554b1782ffd796e7063bcd/setup.py", line 350, in get_hdf5_version
major_version = int(re.split("\s*", line)[2])
ValueError: invalid literal for int() with base 10: 'd'
----------------------------------------
解决方案-这里是到table时出问题了
我妥协了,我直接pip一个算啦
conda install pytorch torchvision cpuonly -c pytorch
pip install Jupyter
以下请忽略
pip install tables-3.4.2-1-cp36-cp36m-win_amd64.whl
错误信息⚠️
WARNING: Requirement 'tables-3.4.2-1-cp36-cp36m-win_amd64.whl' looks like a filename, but the file does not exist
ERROR: tables-3.4.2-1-cp36-cp36m-win_amd64.whl is not a supported wheel on this platform.
或者是
pip install tables
错误信息⚠️
ERROR: Exception:
Traceback (most recent call last):
File "/Users/shenfan/.environments/ai/lib/python3.7/site-packages/pip/_vendor/resolvelib/resolvers.py", line 171, in _merge_into_criterion
crit = self.state.criteria[name]
KeyError: 'tables'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/Users/shenfan/.environments/ai/lib/python3.7/site-packages/pip/_vendor/urllib3/response.py", line 438, in _error_catcher
yield
File "/Users/shenfan/.environments/ai/lib/python3.7/site-packages/pip/_vendor/urllib3/response.py", line 519, in read
data = self._fp.read(amt) if not fp_closed else b""
File "/Users/shenfan/.environments/ai/lib/python3.7/site-packages/pip/_vendor/cachecontrol/filewrapper.py", line 62, in read
data = self.__fp.read(amt)
File "/Users/shenfan/opt/anaconda3/lib/python3.7/http/client.py", line 457, in read
n = self.readinto(b)
File "/Users/shenfan/opt/anaconda3/lib/python3.7/http/client.py", line 501, in readinto
n = self.fp.readinto(b)
File "/Users/shenfan/opt/anaconda3/lib/python3.7/socket.py", line 589, in readinto
return self._sock.recv_into(b)
File "/Users/shenfan/opt/anaconda3/lib/python3.7/ssl.py", line 1071, in recv_into
return self.read(nbytes, buffer)
File "/Users/shenfan/opt/anaconda3/lib/python3.7/ssl.py", line 929, in read
return self._sslobj.read(len, buffer)
socket.timeout: The read operation timed out
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/Users/shenfan/.environments/ai/lib/python3.7/site-packages/pip/_internal/cli/base_command.py", line 189, in _main
status = self.run(options, args)
File "/Users/shenfan/.environments/ai/lib/python3.7/site-packages/pip/_internal/cli/req_command.py", line 178, in wrapper
return func(self, options, args)
File "/Users/shenfan/.environments/ai/lib/python3.7/site-packages/pip/_internal/commands/install.py", line 317, in run
reqs, check_supported_wheels=not options.target_dir
File "/Users/shenfan/.environments/ai/lib/python3.7/site-packages/pip/_internal/resolution/resolvelib/resolver.py", line 122, in resolve
requirements, max_rounds=try_to_avoid_resolution_too_deep,
File "/Users/shenfan/.environments/ai/lib/python3.7/site-packages/pip/_vendor/resolvelib/resolvers.py", line 453, in resolve
state = resolution.resolve(requirements, max_rounds=max_rounds)
File "/Users/shenfan/.environments/ai/lib/python3.7/site-packages/pip/_vendor/resolvelib/resolvers.py", line 318, in resolve
name, crit = self._merge_into_criterion(r, parent=None)
File "/Users/shenfan/.environments/ai/lib/python3.7/site-packages/pip/_vendor/resolvelib/resolvers.py", line 173, in _merge_into_criterion
crit = Criterion.from_requirement(self._p, requirement, parent)
File "/Users/shenfan/.environments/ai/lib/python3.7/site-packages/pip/_vendor/resolvelib/resolvers.py", line 82, in from_requirement
if not cands:
File "/Users/shenfan/.environments/ai/lib/python3.7/site-packages/pip/_vendor/resolvelib/structs.py", line 124, in __bool__
return bool(self._sequence)
File "/Users/shenfan/.environments/ai/lib/python3.7/site-packages/pip/_internal/resolution/resolvelib/found_candidates.py", line 99, in __bool__
return any(self)
File "/Users/shenfan/.environments/ai/lib/python3.7/site-packages/pip/_internal/resolution/resolvelib/factory.py", line 242, in iter_index_candidates
version=ican.version,
File "/Users/shenfan/.environments/ai/lib/python3.7/site-packages/pip/_internal/resolution/resolvelib/factory.py", line 167, in _make_candidate_from_link
name=name, version=version,
File "/Users/shenfan/.environments/ai/lib/python3.7/site-packages/pip/_internal/resolution/resolvelib/candidates.py", line 306, in __init__
version=version,
File "/Users/shenfan/.environments/ai/lib/python3.7/site-packages/pip/_internal/resolution/resolvelib/candidates.py", line 144, in __init__
self.dist = self._prepare()
File "/Users/shenfan/.environments/ai/lib/python3.7/site-packages/pip/_internal/resolution/resolvelib/candidates.py", line 226, in _prepare
dist = self._prepare_distribution()
File "/Users/shenfan/.environments/ai/lib/python3.7/site-packages/pip/_internal/resolution/resolvelib/candidates.py", line 312, in _prepare_distribution
self._ireq, parallel_builds=True,
File "/Users/shenfan/.environments/ai/lib/python3.7/site-packages/pip/_internal/operations/prepare.py", line 457, in prepare_linked_requirement
return self._prepare_linked_requirement(req, parallel_builds)
File "/Users/shenfan/.environments/ai/lib/python3.7/site-packages/pip/_internal/operations/prepare.py", line 482, in _prepare_linked_requirement
self.download_dir, hashes,
File "/Users/shenfan/.environments/ai/lib/python3.7/site-packages/pip/_internal/operations/prepare.py", line 234, in unpack_url
hashes=hashes,
File "/Users/shenfan/.environments/ai/lib/python3.7/site-packages/pip/_internal/operations/prepare.py", line 108, in get_http_url
from_path, content_type = download(link, temp_dir.path)
File "/Users/shenfan/.environments/ai/lib/python3.7/site-packages/pip/_internal/network/download.py", line 163, in __call__
for chunk in chunks:
File "/Users/shenfan/.environments/ai/lib/python3.7/site-packages/pip/_internal/cli/progress_bars.py", line 159, in iter
for x in it:
File "/Users/shenfan/.environments/ai/lib/python3.7/site-packages/pip/_internal/network/utils.py", line 88, in response_chunks
decode_content=False,
File "/Users/shenfan/.environments/ai/lib/python3.7/site-packages/pip/_vendor/urllib3/response.py", line 576, in stream
data = self.read(amt=amt, decode_content=decode_content)
File "/Users/shenfan/.environments/ai/lib/python3.7/site-packages/pip/_vendor/urllib3/response.py", line 541, in read
raise IncompleteRead(self._fp_bytes_read, self.length_remaining)
File "/Users/shenfan/opt/anaconda3/lib/python3.7/contextlib.py", line 130, in __exit__
self.gen.throw(type, value, traceback)
File "/Users/shenfan/.environments/ai/lib/python3.7/site-packages/pip/_vendor/urllib3/response.py", line 443, in _error_catcher
raise ReadTimeoutError(self._pool, None, "Read timed out.")
pip._vendor.urllib3.exceptions.ReadTimeoutError: HTTPSConnectionPool(host='files.pythonhosted.org', port=443): Read timed out.
错误信息⚠️
ERROR: Could not find a version that satisfies the requirement tables==3.4.2
ERROR: No matching distribution found for tables==3.4.2