简体   繁体   中英

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 occured 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.

系统PythonVIRTUALENV

B. Django is not importable in this enviornment

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?

Thank you for your time.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM