#๐Ÿ”’ vs code driving me mad

96 messages ยท Page 1 of 1 (latest)

dim shadow
#

Okay guys I have a problem with the behavior of VS code which is driving me nuts to be honest

So I have a directory structure where I have a bunch of folders where I'm actually writing the actual program and one single folder where I have the utilities kind of folder where I have all of the utilities

Now the problem is whenever I open vs code so that I can see all of the folders including the utilities 1 and then inside of subfolder I'm writing one of the program files and I'm importing one of the modules from one of the utils the problem I'm having is that the python program cannot find that module

Then I have to do this weird hack around where I do

sys.path.append("..")```

and then i also Need to open one of the subfolders as the main folder in VS code for district to work and only then can it import the utils properly so is there a work around around this or is there any other solution to this problem
ripe coveBOT
#

@dim shadow

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

red wolf
#

can u show ur project directory tree

dim shadow
#

here is how it looks

red wolf
dim shadow
dim shadow
red wolf
dim shadow
red wolf
red wolf
dim shadow
dim shadow
#

to show where am i running the file from

red wolf
#

and whats command u using to run this

dim shadow
#

The only reason I'm hiding the path was because one of them has my name in it so instead of just blaring that portion i did some extra as well

dim shadow
#

I'm just using the run arrow from the Visual Studio code app

red wolf
#

what happens if u run it like this

dim shadow
dim shadow
#

its the same

red wolf
#

weird

red wolf
#

ig

#

or just make a venv at labs and that might fix (?)

dim shadow
dim shadow
red wolf
dim shadow
#

O k so you want me to create a virtual environment over here and what else

wet yew
#

Gah.

dim shadow
#

And it should be in which directly the labs directory should have it with all of the 4 folders or should it be in one of the sub folders

wet yew
#

You don't need a venv for this. (They're very useful, but irrelevant here.)

dim shadow
red wolf
wet yew
#

Just ensure that the folder containing LinearStructures is in your sys.path. Python gets that from the $PYTHONPATH environment variable, and VSCode should have some hook for setting that.

dim shadow
#

But if it fixes this issue that I am having which is driving me crazy I am happy to implement it

dim shadow
wet yew
#

You can also do this with a venv by (a) making one (b) pointing VSCode at that venv and (c) installing the LinearStructures in the venv.

Feels elaborate.

wet yew
dim shadow
#

Any other solution which is less absurd

dim shadow
#

They especially helpful when you're having a bunch of different Libraries and different python versions and stuff like that

#

anyhow over here how can I get the linear structure folder inside the path

dim shadow
wet yew
red wolf
dim shadow
#

how do i enter terminal settings??

wet yew
#

"Activating" a venv puts the venv's bin at the front of your shell executation path so that python3 (or py etc) find the venv python. In VSCode, it may cause VSCode to invoke the venv python directly.

Regardless, the effect is that when you invoke the python3 from the venv is put's the venv's libraries in the sys.path automatically.

Then you just instal your extra libs in the venv.

For the OP, probably installing an "editable" version of LinearStructures. Which is basicly a symlink to that, in the site-poackages.

wet yew
red wolf
dim shadow
wet yew
#

No, it puts the venv libs in the sys.path.

red wolf
wet yew
#

Note that when you invoke a script as:

py /path/to/the/script.py

(which is how VSCode runs things in the terminal window), Python puts /path/to/the at the front of the sys.path automatically. So If the OP's script were in the folder containing LinearStructures it might "just work". But that's fortuitous, not controlled.

dim shadow
wet yew
dim shadow
wet yew
dim shadow
#

So I have a parent folder which has 4 subfolders and the programs are in 3 of those subfolders with the remaining one being linear structs where the imported modules are

wet yew
#

Oh, that's horribly unreadable. Discord scaling things down I guess.

red wolf
dim shadow
#

i am at awe

#

props to you for making sense from that color scheme

wet yew
#

That's a 16 inch macbook pro laptop display. Just one 3072x1920 screen. One full-screen iTerm window broken into 2 terminals side by side, a shell in the right and vim in the left. Vim split into 2 windows (files).

red wolf
#

for a moment i thought u just had installed some vim plugins and made 1 giant battlestation

wet yew
#

Nay. I ise iTerm to multiplex terminal windows. See the tabs on the left? A tab per python work area.

dim shadow
wet yew
#

No, an older intel one.

dim shadow
#

Because I have just recently seen the 16 inch Macbook Pro laptop with one of my friends and it wasn't that big to be honest

#

to manage all that one screen is mega

#

man is crazy and talented at the same time

wet yew
#

It's the same size. I run in native resolution. Macs default to a lower "logical" pixel count with subpixel dithering for nice rendering.

#

I just want lots of characters in my terminals.

wet yew
wet yew
dim shadow
#

the magnifier just distorts the image to be honest

wet yew
#

Anyway. The terminal window on the right has the dev environment available.

CSS[~/hg/css(hg:default)]fleet2*> py3
+ exec /Users/cameron/tmp/venv--css--apple.x86_64.darwin/bin/python3
Python 3.13.1 (main, Dec  3 2024, 17:59:52) [Clang 16.0.0 (clang-1600.0.26.4)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> sys.path
['/Users/cameron/hg/css/lib/python', '/Users/cameron/p/lib/python', '/Users/cameron/lib/python', '/Users/cameron/rc/python', '/Users/cameron/var/homebrew/Cellar/[email protected]/3.13.1/Frameworks/Python.framework/Versions/3.13/lib/python313.zip', '/Users/cameron/var/homebrew/Cellar/[email protected]/3.13.1/Frameworks/Python.framework/Versions/3.13/lib/python3.13', '/Users/cameron/var/homebrew/Cellar/[email protected]/3.13.1/Frameworks/Python.framework/Versions/3.13/lib/python3.13/lib-dynload', '/Users/cameron/tmp/venv--css--apple.x86_64.darwin/lib/python3.13/site-packages']
>>>

So for me, typing py3 invokes the python3 from the venv I'm using. But also there's a $PYTHONPATH variable.

In the sys.path above these:

'/Users/cameron/hg/css/lib/python', '/Users/cameron/p/lib/python', '/Users/cameron/lib/python', '/Users/cameron/rc/python'

come from the $PYTHONPATH and the rest come from the venv python3 executable: the base homebrew python, then the venv site-packages at the end.

#

Does this make things any clearer?

#

@dim shadow ??

ripe coveBOT
#
Python help channel closed for inactivity

This help channel has been closed. Feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.