I Get ImportError: No module named pathlib, even after installing pathlib with pip

感情迁移 提交于 2021-01-29 07:11:29

问题


This is my first time asking on this site, so sorry if my question is not layed out correctly

y@DESKTOP-MQJ3NCT:~/Real-Time-Voice-Cloning$ python demo_toolbox.py
Traceback (most recent call last):
  File "demo_toolbox.py", line 1, in <module>
    from pathlib import Path
ImportError: No module named pathlib

I have tried:

pip3 install pathlib

and:

sudo -H pip3 install pathlib

but continue to get the same error

I am using the windows store version of ubuntu 18 LTS and python 3.7


回答1:


Sorry, turns out it was a simple mistake!

Instead of:

python demo_toolbox.py

I should have used

python3 demo_toolbox.py

As Linux defaults to Python 2 or something incompatible with pathlib




回答2:


When it comes to python, it's quite easy to make the mistake of just running "python ...". When you install python on windows "python" defaults to the python 2.7 installation ( probably changed now that 2.7 is no longer supported) if it is installed.

Ubuntu has the links "python2" and "python3" which makes so much more sense but can still lead to confusion.

If you have a local python Virtual environment, the "python" command defaults to the global install on windows (to further confuse people).

I find it generally best to create my own links to the global python "python27" and "python36" to avoid these confusions.

Same goes for pip. It's best to call

python3 -m pip install ... 

Also. PyCharm is the most amazing Python IDE in the world and it helps with so much.



来源:https://stackoverflow.com/questions/60788709/i-get-importerror-no-module-named-pathlib-even-after-installing-pathlib-with-p

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!