Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Visual Studio Code .env file does not provide access to PYTHONPATH #94338

Closed
pjgoodall opened this issue Apr 3, 2020 · 12 comments
Closed

Visual Studio Code .env file does not provide access to PYTHONPATH #94338

pjgoodall opened this issue Apr 3, 2020 · 12 comments
Assignees
Labels
*caused-by-extension Issue identified to be caused by an extension info-needed Issue requires more information from poster

Comments

@pjgoodall
Copy link

Problem

I expect to be able to import from modules with subdirectories of the vscode workplaceFolder.
If I try to append to PYTHONPATH using the environment file: ${workspaceFolder}/.env, I get an empty reference to PYTHONPATH within that file. I therefore cannot add the path to my modules to PYTHONPATH from ${workspaceFolder}/.env

I do not want to hard-code a manipulation of the environment into my python source.

This may be an interaction complexity between vscode and conda virtual environments

Files to recreate the environment, and further documentation are in the public github repository https://github.com/pjgoodall/test_vscode_env

@jrieken jrieken added the info-needed Issue requires more information from poster label Apr 3, 2020
@jrieken
Copy link
Member

jrieken commented Apr 3, 2020

what are trying to achieve? debug? run task?

@pjgoodall
Copy link
Author

pjgoodall commented Apr 3, 2020 via email

@pjgoodall
Copy link
Author

pjgoodall commented Apr 3, 2020 via email

@jrieken
Copy link
Member

jrieken commented Apr 3, 2020

So, what isn't working you? What you are trying to achieve? What is the actual and expected behaviour?

@pjgoodall
Copy link
Author

Thanks for your kind attention Johannes,

I'm not sure what isn't clear from the problem description at the top, and the linked repository. So I will try and restate my problem - which could be a misunderstanding on my part. I have also updated the example code in my linked repository: https://github.com/pjgoodall/test_vscode_env

What I'm trying to achieve

Structure a project so I can have separate subdirectories which have .py files which I am using to explore various libraries without cluttering my main development sources. I want all my project efforts in the same simple git-controlled hierarchy.

For instance I need to try out python logging, and interactions between pandas and threading. An example: ThreadPool(2).imap_unordered(acceptTuple, sample.itertuples(index=None))

They are non-trivial explorations (for me). As I evolve them towards being useful in my project I want to be able to import from the libraries I have developed for my main project. The libraries are in sibling directories to my exploration directories. I want to manage access to these libraries not hard-coded into my python source. To separate configuration from code - I don't want to encode paths into my source-code as suggested in stack exchange:

  • os.path.append("dir/to/your/library")
  • sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))

What isn't working for me

I asked this question on stackexchange originally. Please read.

After a bunch of docs - which I must say are confusing when trying to put them together, I imagined the inconsistency between my command-line environment and the debugger in vscode (see my stack-exchange post, linked above) could be resolved by moving the PYTHONPATH from using environment variable values configured using conda and autoenv,

conda activate GBIF-REST-API
autostash PATH=$PWD:$PATH
autostash PYTHONPATH=$PWD:$PWD/python_modules

into the vscode ${workspaceFolder}/.env file.

I assumed that PYTHONPATH would normally be set in any python environment. It is not apparently set by default in conda environments. Conda seems totally focussed on runtime libraries - so PYTHONPATH is probably a configuration liability for them whereas I believe it gives needed flexibility during development.

The problems are:

  • I cannot sync the 'run' and 'debug' environments using the ${workspaceFolder}/.env file. If you don't see this effect, try editing the .env file from within vscode. I suspect there is a file-watching update difference between the debug and run environments.

  • I cannot set the PYTHONPATH environment variable from ${workspaceFolder}/.env. This does not work for either the run or debug functions.

My updated tests should show this. https://github.com/pjgoodall/test_vscode_env

Cheers,
--Peter G

@pjgoodall
Copy link
Author

pjgoodall commented Apr 5, 2020

I'm also starting to think ${workspaceFolder}/.env is not of use because its effects are not available to the direct command-line. But the vscode debug environment doesn't seem to see the enclosing environment. Quite confusing - vscode is a festival of settings :-)

@jrieken
Copy link
Member

jrieken commented Apr 6, 2020

Ok, I believe this should have been filed here: https://github.com/Microsoft/vscode-python. We only provide the "framework" in which python support operates and have little knowledge about its internals.

@jrieken jrieken self-assigned this Apr 6, 2020
@pjgoodall
Copy link
Author

Thanks Johannes,
Are you able to re-file this appropriately?
My apologies. This is the first time I’ve really used both python and vscode determinedly.
Cheers,
—Peter G

@jrieken
Copy link
Member

jrieken commented Apr 8, 2020

I also cannot simply transfer the issue....

@jrieken
Copy link
Member

jrieken commented Apr 8, 2020

/extPython

@pjgoodall
Copy link
Author

Well not being able to transfer surely sucks

@github-actions github-actions bot locked and limited conversation to collaborators May 23, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
*caused-by-extension Issue identified to be caused by an extension info-needed Issue requires more information from poster
Projects
None yet
Development

No branches or pull requests

3 participants
@pjgoodall @jrieken and others