PyCharm Pro ImportError and Broken Virtualenv

Issue: The solution was to uninstall the virtualenv.

While I was trying to set-up a Django Project. On the manage.py:

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?"
) from exc

Update: I ran virtualenv cmd in Pycharm Pro terminalThis came up:

You must provide a DEST_DIR
Usage: virtualenv [OPTIONS] DEST_DIR

installation and virtualenv is installed.

5

2 Answers

from django.core.management import execute_from_command_line works perfectly plus you are getting the following error when using python3.7 interpreter in Ubuntu 19.04:

You must provide a DEST_DIR
Usage: virtualenv [OPTIONS] DEST_DIR

The PyCharm terminal is like the default Ubuntu terminal except that it can be used within the PyCharm application. It looks to me like there is a typo in your question and instead of running virtualenv cmd which would have worked in the terminal you ran virtualenv which wouldn't have worked.

You got the following additional error in PyCharm.

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?)

That looks like another typo error. The correct command to import Django is import django not import Django.

If import django doesn't work either then you need to tell PyCharm to look for Python packages that were installed from the default Ubuntu repositories when you create a new project. If any of the project's Python packages are installed from the default Ubuntu repositories PyCharm will find them automatically if you select the Inherit global-site packages option when you create a new project.

Select File -> New Project to create a new project. Click the triangle marked by the mouse cursor in the below screenshot to show the new project's options.

Create Project

Then check the Inherit global-site packages checkbox and click the Create button in the lower right corner of the Create Project window.

Create Project options

0

The broken virtualenv was causing the import error the whole time. The only solution was to uninstall the virtualenv and it's dependencies. Here's all the cmd I used tried with in order:

 sudo apt-get remove --auto-remove python-virtualenv sudo apt-get remove python-virtualenv sudo apt-get remove virtualenv

To ensure all the virtualenv was uninstalled.

The python3 venv still remains as it should be.

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like