If you have your project in a virtual environment and you want add the project in eclipse so that the project uses libraries that are installed on the virtual environment, then you should follow the following steps.
step 1: let‘s say the absolute path to your virtual environment is: C:\Users\sadegh\Desktop\flask_eclipse\fe\venv
![技术分享图片](https://i.stack.imgur.com/khSfE.jpg)
go to window->preferences->PyDev->interpretors->Python Interpretor
in the Scripts
directory, there is python.exe
which is the python interpreter that has been assigned to this virtual environment. This executable will be the new python interpreter that we will add to eclipse.
step2: Go to window->preferences->PyDev->Interpreters->Python Interpreter
![技术分享图片](https://i.stack.imgur.com/NYZvg.jpg)
In the right pane you will see this: ![技术分享图片](https://i.stack.imgur.com/1FJNQ.jpg)
click on new button then this window will pop up: ![技术分享图片](https://i.stack.imgur.com/rRS8Z.jpg)
write anything you want in the Interpreter Name
field and write the absolute path of the python.exe file that was mentioned in step 1 in the Interpreter Executable
field
after clicking OK
this will pop up: ![技术分享图片](https://i.stack.imgur.com/YPODO.jpg)
select all the items then click OK
step3: select the newly added interpreter in the above pane, then in the below pane go to Forced Builtin
tab and click on new button on right hand side of this below pane.
![技术分享图片](https://i.stack.imgur.com/WNa5O.jpg)
and in the window that pops up write flask.ext
.
step4: everything is set now:
if you want to start a new project: when you are creating a new PyDev Project
select the new Interpreter that we created as the Interpreter of this project. ![技术分享图片](https://i.stack.imgur.com/k7fPY.png)
if you want to convert an existing project to a flask project on your virtual environment right click on project and go to properties and in PyDev-Interpreter/Grammar
change the Interpreter to the new interpreter that we have created.
note: If you want the eclipse to run the server for you in the virtual environment you can run the server from within the code that contains the Flask() instance like this:
if __name__ == ‘__main__‘: #here i assume you have put this code in a file that
app.run() #contains variable "app", which contains the instance of #Flask(__main__)