Reputation: 272
When I have a python project in VS 2017 and create a new python package (folder and __init__.py file) with the "Add->New File" menu, everything works as intended: IntelliSense recognized the package, I can import and use it.
But if I manually create a folder and __init__.py file, then I can still import and the code works fine, but IntelliSense is not picking up the new module. How can I manually include this existing package into the python project?
Upvotes: 0
Views: 643
Reputation: 272
Perry Qian-MSFT's answer unfortunately did not work for me (more on that in the comment under his answer), but what did work was the same approach as this answer to How do I add an existing directory tree to a project in Visual Studio?
Upvotes: 2
Reputation: 23770
How to add existing package in Python project in Visual Studio 2017 (for IntelliSense)
It is quite strange and it seems that you have created such folder in its physical path which contains a self-created file called __init__.py
, but it works well in my side and I can get the Intellisense from the new module. You can follow my steps:
Step
1) I have created a folder called package 3
and add a file called __init__.py
under the physical path manually.
2) then open VS, start the project, right-click on it-->Add-->Existing Folder-->add package 3 into it. Then it will import the package 3 folder and its content into Solution Explorer.
3) if you want to use new module in package 3
's __init__.py
, you could use import node in init.py(package 3) :
import module1;
In addition, if Intellisense does not work either, you should close VS Instance, delete .vs
hidden folder under solution folder, then restart the project again to test it. You can try it several times.
Upvotes: 1