0

After updating Ubuntu to the latest update, Pycharm tells me required packages are missing but the virtual environment is activated and the packages are all there.

Trying to runserver results in ImportError: Couldn't import Django. Are you sure it's installed and available on your PYTHONPATH environment variable? Did you forget to activate a virtual environment?

Trying to install packages again results in Invalid Python SDK

Anyone having this problem after the update? Thanks in advance.

EDIT: Creating a new venv seems to be a simply and fool-proof solution.

When using python3 it used the python at locate at /usr/bin/python3 instead of /venv/bin/python3.

It behaves like the venv isn't activated, while it actually is. The venv directory in the project is immutate but it seems like Pycharm doesen't recognize it.

Looking at the interpreter seems like no package is installed or can be installed (both with gui or cli).

In the case this is a commonly experienced problem, please use this question for further investigations.

6
  • Could you verify which python are you using by running which python3 ?
    – farch
    Commented Apr 28, 2022 at 8:12
  • the output is /usr/bin/python3 the version is 3.9
    – atianalisi
    Commented Apr 28, 2022 at 8:19
  • 1
    What happens if you use python binary in your virtual environment <virtual-env-path>/bin/python3 manage.py runserver ?
    – farch
    Commented Apr 28, 2022 at 8:22
  • python3 in venv/bin is an invalid symlink, it doens't run.. didn't notice this
    – atianalisi
    Commented Apr 28, 2022 at 8:33
  • try to recreate your virtual environment, but run this command first python3 -m pip --user virtualenv packaging.python.org/en/latest/guides/…
    – farch
    Commented Apr 28, 2022 at 8:44

1 Answer 1

0

As the exact Python version and the paths to the system libraries might change with the update, the created venvs might also break.

Therefore, it is always recommended to recreate all venvs after updating the system.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.