Could not install packages due to an EnvironmentError/OSError: [Errno 39] Directory not empty: 'xxx'

Could not install packages due to an EnvironmentError/OSError: [Errno 39] Directory not empty: 'xxx'錯誤及解決方式

前言

筆者曾經碰過這個錯誤兩次,雖然錯誤訊息不太一樣,但仍然可以採用相同的解決辦法。

發生場景1

這是筆者在使用pip升級notebook這個包時所出現的錯誤:

pip install notebook --upgrade

pip輸出訊息的前半部只是從網路下載包的log,以下展示的是比較重要的後半部份。

Installing collected packages: tornado, ptyprocess, terminado, jupyter-core, nbformat, six, bleach, testpath, MarkupSafe, jinja2, mistune, pygments, defusedxml, nbconvert, pyzmq, python-dateutil, jupyter-client, prompt-toolkit, backcall, decorator, parso, jedi, pickleshare, setuptools, pexpect, ipython, ipykernel, prometheus-client, Send2Trash, notebook
Found existing installation: tornado 4.5.1
Uninstalling tornado-4.5.1:
Exception:
Traceback (most recent call last):
File “/usr/lib/python3.5/shutil.py”, line 538, in move
os.rename(src, real_dst)
OSError: [Errno 18] Invalid cross-device link: ‘/usr/local/lib/python3.5/dist-packages/tornado-4.5.1-py3.5.egg-info’ -> ‘/tmp/pip-zlc_di8p-uninstall/usr/local/lib/python3.5/dist-packages/tornado-4.5.1-py3.5.egg-info’

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File “/usr/local/lib/python3.5/dist-packages/pip/basecommand.py”, line 215, in main
status = self.run(options, args)
File “/usr/local/lib/python3.5/dist-packages/pip/commands/install.py”, line 342, in run
prefix=options.prefix_path,
File “/usr/local/lib/python3.5/dist-packages/pip/req/req_set.py”, line 778, in install
requirement.uninstall(auto_confirm=True)
File “/usr/local/lib/python3.5/dist-packages/pip/req/req_install.py”, line 754, in uninstall
paths_to_remove.remove(auto_confirm)
File “/usr/local/lib/python3.5/dist-packages/pip/req/req_uninstall.py”, line 115, in remove
renames(path, new_path)
File “/usr/local/lib/python3.5/dist-packages/pip/utils/init.py”, line 267, in renames
shutil.move(old, new)
File “/usr/lib/python3.5/shutil.py”, line 550, in move
rmtree(src)
File “/usr/lib/python3.5/shutil.py”, line 478, in rmtree
onerror(os.rmdir, path, sys.exc_info())
File “/usr/lib/python3.5/shutil.py”, line 476, in rmtree
os.rmdir(path)
OSError: [Errno 39] Directory not empty: ‘/usr/local/lib/python3.5/dist-packages/tornado-4.5.1-py3.5.egg-info’
You are using pip version 9.0.1, however version 18.1 is available.
You should consider upgrading via the ‘pip install --upgrade pip’ command.

發生場景2

python -m pip install --upgrade --force pip

Collecting pip
Downloading https://files.pythonhosted.org/packages/c2/d7/90f34cb0d83a6c5631cf71dfe64cc1054598c843a92b400e55675cc2ac37/pip-18.1-py2.py3-none-any.whl (1.3MB)
Installing collected packages: pip
Found existing installation: pip 18.1
Uninstalling pip-18.1:
Could not install packages due to an EnvironmentError: [Errno 39] Directory not empty: ‘/root/miniconda/envs/test-environment/lib/python2.7/site-packages/pip/_internal/cli’

The command ‘/bin/sh -c /$HOME/miniconda/envs/test-environment/bin/python -m pip install --upgrade --force pip’ returned a non-zero code: 1

解決辦法

解決辦法就是在後面加上--ignore-installed,變成:

pip install notebook --upgrade --ignore-installed

python -m pip install --upgrade --force --ignore-installed pip
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值