Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using virtualenv in Pycharm as Django IDE

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 PythonVirtualenv

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?

like image 430
CppLearner Avatar asked Jan 02 '12 01:01

CppLearner


1 Answers

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.

like image 74
ashwoods Avatar answered Oct 25 '22 07:10

ashwoods