PyCharm + Flask: Unresolved link. How do I import Python namespaces correctly?

I added a virtual environment Flask

and Flask-Script

in PyCharm

. The app works, but PyCharm

gives me various errors:

Unresolved reference "Manager" (from  flask.ext.script import Manager)
Cannot find reference "script" in "__init__.py" (from  flask.ext.script import Manager)
No module named "script" (command = flask.ext.script.Command(app)

      

As a result, code completion does not work.

So, if I import modules directly, like import flask_script code completion, but I'm not sure if that is the intended use!

I can fix this if I import flask_script

directly instead flask.ext

. Is this a valid workaround?

Is there any other other way to solve this? I have read several answers, but none of them seem to address this issue.

+4


source to share


4 answers


In your venv> lib> python3.x> site-packages, mark site-packages as the original root.



+8


source


Go to File β†’ Default Settings β†’ Project Translator Add your own translator. Then add the Flask package by clicking the plus sign. It will close the whole module.



It works for me!

+1


source


I had a similar error: "Can't find reference" Flask "in" flask.py ".

If you are on Windows (using Pycharm) go to Files β†’ Project Interpreter. There will be a list of packages, find Flask and open it by double clicking on it. Then click install package, it will install it for your project.

I don't know about it in detail, but this is how I solved my problem.

0


source


You must tell PyCharm which interpreter you are using. Let's say you are using some virtualenv, on Mac (similar to Linux) go to File> Default Settings> Project Interpreter

Then click on the little mechanical wheel next to the project translator drop-down menu, select "add local" and select your translator (for example, the virtual environment where you installed the flash drive).

Hope this helps.

-1


source







All Articles