如果我嘗試使用 pip 安裝某些東西,例如python3 -m pip install torch==1.9.1 cu111 --find-links https://download.pytorch.org/whl/torch_stable.html我收到以下錯誤:
Traceback (most recent call last):
File "/usr/lib/python3/dist-packages/pip/basecommand.py", line 215, in main
status = self.run(options, args)
File "/usr/lib/python3/dist-packages/pip/commands/install.py", line 290, in run
with self._build_session(options) as session:
File "/usr/lib/python3/dist-packages/pip/basecommand.py", line 69, in _build_session
if options.cache_dir else None
File "/usr/lib/python3.6/posixpath.py", line 80, in join
a = os.fspath(a)
TypeError: expected str, bytes or os.PathLike object, not int
這會引發相同的錯誤:python3 -m pip install --user torch==1.9.1 cu111 --find-links https://download.pytorch.org/whl/torch_stable.html. 安裝可以sudo完成這項作業,但似乎不正確。我該如何修復我的點子?我使用的是 Ubuntu 18.04 和 Python 3.6
uj5u.com熱心網友回復:
嘗試
python3 -m pip install --user torch==1.9.1 cu111 --find-links https://download.pytorch.org/whl/torch_stable.html
這將安裝到您的用戶目錄中。
編輯
pip安裝包的確切位置取決于許多因素,包括是否使用虛擬環境或第三方環境管理器(例如 conda)。它當然也取決于作業系統和版本。有很多專門針對該主題的博客和 SO 帖子,例如這個。
默認情況下,如果既不使用 virtual env 也不使用 conda,則大多數 Linux 版本上最近的 python/pip 版本都會寫入/usr/lib[64]或/usr/local/lib[64],兩者都是 root 可寫的。一種可能的解決方法是使用該--user標志,如上所述。
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/315724.html
