Issue
Currently, I am developing a Django web app in a virtual environment but when I try to edit the web app it just seems that the libraries that I installed in the virtual environment are not found. This is the scenario I have:
I installed a virtual environment in
C:\Users\myUser\PycharmProjects
.mkdir virtualenvs ; cd virtualenvs python -m venv virtualenvs
I got access to the new folder, activated the virtual environment, upgrading pip and started installing the libraries I need for my project.
cd C:\Users\myUser\PycharmProjects\virtualenvs\virtualenvs\Scripts ; .\activate (virtualenvs) python -m pip install --upgrade pip (virtualenvs) pip install django djangorestframework pandas numpy requests
I go back to
C:\Users\myUser\PycharmProjects
to create my new Django project (I am still inside of my virtualenvs).(virtualenvs) mkdir C:\Users\myUser\PycharmProjects\apps ; cd C:\Users\myUser\PycharmProjects\apps (virtualenvs) django-admin.exe startproject app1 (virtualenvs) python manage.py startapp web_app_navigator (virtualenvs) python manage.py runserver
I am able to see the Django successful message
The install worked successfully! Congratulations!
, but when I open this new application in PyCharm to do some changes such as trying to import any library that I installed I get an error message that the library is not found.
My guess is that the virtualenvs and app folder is in some way disconnected from the Pycharm editor, so this might be the reason why PyCharm cannot find the libraries I installed. The easy solution should be to avoid using the virtual environment and just download the libraries but I am against this idea because I want to maintain each Django web app separated with its own libraries.
Did I miss any step such as connecting the app folder with the virtual environment folder? How can I make the virtual environment to work correctly in Pycharm? Any comment, suggestion or improvement to this question is greatly appreciated.
Solution
virtualenv
tool comes bundled with PyCharm, You just need to install it by following these steps.
Steps to Create Virtual Environment
Open the
Settings
dialog box, by going on left and clicking on file and going down the dropdown and selectSettings
or alternatively hitCtrl+Alt+S
.Click on your project on left and then click on
Project Interpreter
this opens a window on right.Now just choose
Create VirtualEnv
from dropdown inProject Interpreter
if it is not there then click small button on right and selectCreate VirtualEnv
. CAVEAT: In case this option does not appear, click on existing environment, select the Interpreter option and click on the...
button to look for your virtual environment setup. In your case, you should selectC:\Users\myUser\PycharmProjects\virtualenvs\virtualenvs\Scripts\python.exe
. Remember that the Scripts folder contains all the libraries that have been downloaded when you created the virtual environment. Select apply and hit OK, so now you should be able to see all your libraries that were downloaded.Now in the
Create Virtual Environment
Window , give Name to your VirtualEnv choose Location to install and choose Base Interpreter from dropdown or by clicking button on right, Base Interpreter is the Python Interpreter.Click Ok and your new VirtualEnv is created.
Answered By - Astik Anand
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.