Django新手部署时安装PythonAnywhere Helper Tool报错求助
Hey there, let's fix this issue you're hitting! The error ImportError: No module named pathlib pops up because the pythonanywhere package relies on pathlib—a module that's only built into Python 3.4 and newer versions. Since you're running Python 2.7 (which has been end-of-life for years now), your environment doesn't have this module by default.
Here are two ways to resolve this:
推荐方案:切换到Python3环境
Python 2.7 is no longer supported, so moving to Python3 is the best long-term fix. Let's check if you already have it installed:
python3 --version
If it shows a version like 3.4+, install the pythonanywhere package using pip3 instead:
pip3 install --user pythonanywhere
If Python3 isn't on your system yet, install it first with these commands:
sudo apt-get update sudo apt-get install python3 python3-pip
临时方案(不推荐):给Python2.7安装pathlib兼容包
If you absolutely need to stick with Python2.7 for now, you can install pathlib2—a third-party port of pathlib that works with Python2:
pip install --user pathlib2
After that, try installing pythonanywhere again. Keep in mind though, you might run into other compatibility issues later since most modern packages don't support Python2 anymore.
为什么会出现这个错误?
The setup script for the pythonanywhere package imports pathlib directly, assuming you're using a modern Python version. Since Python2.7 lacks this built-in module, the installation fails right at the start.
内容的提问来源于stack exchange,提问作者Pravin Kamble

