Using virtualenv in Pycharm as Django IDE

11,691

First, no need to create a symlink, as the add interpreter dialog has a button 'show hidden files and directores', and you can manually type in the path too.

Each virtualenv is, since version 1.7, an isolated environment by default . That means you have to explicitly pass the --system-site-packages ENV if you want to automatically include the systems libraries (before 1.7 you had to pass the no-site-packages option if you wanted an isolated env)

So my first guess is that you simply haven't installed the libraries you are missing inside your virtualenv. Check the output of pip freeze after activating your virtualenv. If those libraries are missing, just install them with pip:

pip install django

Now, as you seem to using the non-default python for your virtualenvs, make sure you are not using the system one instead. You can also invoke it directly by using the one under the /bin directory of your virtualenv.

Share:
11,691
CppLearner
Author by

CppLearner

Thanks for helping. I believe when one teaches, two learns.

Updated on June 17, 2022

Comments

  • CppLearner
    CppLearner almost 2 years

    Please help me on this. I am doing this on Fedora 16.

    My virtual environment is /home/username/Desktop/.pythonenv

    Now, notice the dot. Because it is a hidden directory, I had to make a symbolic link in order to for Pycharm to "enter" the directory.

    sudo ln -s /home/yeukhon/Desktop/.pythonenv /home/yeukhon/Desktop/sypythonenv
    

    Now I can use this virtual environment. However, two problems occurred and I am not sure if first one has anything to do with the second one.

    A. Missing GTK and GST

    Here are the two screenshots. The virtualenv python is missing GTK and GST... I have no idea why.

    System Python Virtualenv

    B. Django is not importable in this environment

    I tried to Run my Django project under virtualenv (project1) but I can't. I can run the same project through Terminal.

    [yeukhon@localhost ~]$ cd Desktop/djangoapp/project1
    [yeukhon@localhost mysite]$ source /home/yeukhon/Desktop/.pythonenv/project1/bin/activate
    (project1)[yeukhon@localhost mysite]$ python2.7 manage.py runserver
    # I had to use python2.7 instead of python. That's the only problem with terminal here.
    

    Question

    1. How do I make it runable in PyCharm with my virtualenv Python interpreter?

    2. Does #1 has anything to do with #2?

    3. How do I make GTK and GST appear in my virtualenv?

  • CppLearner
    CppLearner over 12 years
    Hi. Thank you very much for helping me. Question: For your second point, does that defeat the purpose of "isolated envrionement"? Or should I pip install gtk and gsk on my own? I guess it's fine to use sys default libraries as the virtualenv is useful for the non-sys libraries that I am going to be installing in the future. Thanks.
  • ashwoods
    ashwoods over 12 years
    it just depends on what you need. There are some libraries that people like to install via their distribution, i.e. PIL, so that they don't have to install the dependencies to compile them. Personally, I don't use with-site-packages.
  • ashwoods
    ashwoods over 12 years
    others just install their project relevant libs in a virtualenv, those that are bound to change a lot from one project to another. I even use pythonbrew to isolate and manage the python interpreters themselves.
  • CppLearner
    CppLearner over 12 years
    Hi ashwoods. When I use virtualenv I can't use code completion (references cannot be resolved). My virutalenv seems to have problems. What django settings / libraries are missing? I am able to create apps, run django using virtualenv from command lines. Thank you very much.