1

I am using Pylance extension in Visual Studio Code. It can give me hints about different function names and their attributes etc. based on the modules that I have imported.

It works fine for modules installed with pip install module. However, it cannot detect functions which I imported from my own file in a custom location. I import the file like this:

import sys, os
file_loc = "D:\\Work\\assets\\includes\\"
sys.path.append(os.path.dirname(file_loc))
from funcs import *

So, Pylance (or Visual Studio Code) cannot show me any information about functions defined in funcs. I also added my folder to the Environment Path variable but that did not help either.

What should I do?

Thanks.

1 Answer 1

3

You can use pip to add your own files to the environment. I would very much recommend doing it in a virtual environment manager like Anaconda. So activate your virtual environment and write this in the terminal.

pip3 install --editable "D:\\Work\\assets\\includes\\"

The --editable part lets you change the contents of funcs.py and have it show up immediately in your code (very useful when you are using notebook features).

And I would always recommend that you do

from funcs import function_1, function_2

for the sake of your own sanity. It can get confusing in the long run. And be careful with very generic names for your .py files. Put a numbers.py in your folder and it could really mess with your Python ;)

Edit: Oops, meant to add this link to a Reddit post that explains it in more detail than I have here: https://www.reddit.com/r/learnpython/comments/ayx7za/how_does_pip_install_e_work_is_there_a_specific/ei407ao?utm_source=share&utm_medium=web2x&context=3

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.