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

os.environ['PATH'] will raise KeyError(key) when using Ctrl+F5 or only F5. #436

Closed
KryptonLee opened this issue Dec 15, 2017 · 19 comments · Fixed by #466
Closed

os.environ['PATH'] will raise KeyError(key) when using Ctrl+F5 or only F5. #436

KryptonLee opened this issue Dec 15, 2017 · 19 comments · Fixed by #466
Assignees
Labels
area-debugging bug Issue identified by VS Code Team member as probable bug
Milestone

Comments

@KryptonLee
Copy link

Environment data

VS Code version: 1.19.0
Python Extension version: 0.9.0
Python Version: 3.5.2
OS and version: Ubuntu 16.04 64bit

Actual behavior

os.environ['PATH'] will raise KeyError(key) when running a program using Ctrl+F5 or only F5.
But everything is fine when running the program in the console.

Expected behavior

os.environ['PATH'] should get the environment variable PATH.

Steps to reproduce:

  • Update Python Extension to version 0.9.0
  • Run a program with code "import os; print(os.environ['PATH'])" using Ctrl+F5 or only F5
@DonJayamanne DonJayamanne added area-debugging bug Issue identified by VS Code Team member as probable bug awaiting 2-PR labels Dec 15, 2017
@DonJayamanne DonJayamanne added this to the January 2018 milestone Dec 18, 2017
DonJayamanne added a commit that referenced this issue Jan 3, 2018
Refactor how environment variables are parsed and used in tools, language server and debugger

Fixes #316 (PYTHONPATH not used as extra path for auto complete)
Fixes #183 (changes to .env file requires restarts of vscode)
Fixes #436 (Path variables not inherited when debugging)
Fixes #435 (Virtual environment name is same as the default environment file)
@QQQYang
Copy link

QQQYang commented Jan 13, 2018

@KryptonLee Hi, I met the same issue. How to solve it?

@DonJayamanne
Copy link

@KryptonLee this will be fixed in the best release.

@Ansarimi
Copy link

I still see this problem. Why was this closed?

@DonJayamanne
Copy link

It has been closed as the issue has been fixed. We haven't released a new version with the fixes though.
@KryptonLee @Ansarimi @QQQYang Please could you install the insiders build and confirm this works as expected. Here's the link with instructions https://github.com/Microsoft/vscode-python/blob/master/CONTRIBUTING.md#insiders-build

@huppyflup
Copy link

I had the same issue.
Python Extension: 0.9.1
vscode: 1.19.2
Python: 3.6.3
OS: Ubuntu 17.10

2018.1.0-alpha works as expected.

@creepteks
Copy link

I still have this problem. I'm on latest vscode version. should I use insiders build to solve this problem?
I used venv inside my working directory.

Traceback (most recent call last):
File "/home/neo/code/stego_wavelets/wave.py", line 1, in
import pywt
File "/home/neo/code/stego_wavelets/lib/python3.5/site-packages/pywt/init.py", line 16, in
from ._extensions._pywt import *
File "init.pxd", line 155, in init pywt._extensions._pywt (pywt/_extensions/_pywt.c:32567)
File "/home/neo/code/stego_wavelets/lib/python3.5/site-packages/numpy/init.py", line 126, in
from numpy.config import show as show_config
File "/home/neo/code/stego_wavelets/lib/python3.5/site-packages/numpy/config.py", line 9, in
os.environ["PATH"] += os.pathsep + extra_dll_dir
File "/usr/lib/python3.5/os.py", line 725, in getitem
raise KeyError(key) from None
KeyError: 'PATH'

this is my project launch.json python debug config:
{
"name": "Python",
"type": "python",
"request": "launch",
"stopOnEntry": true,
"pythonPath": "${config:python.pythonPath}",
"program": "${file}",
"cwd": "${workspaceFolder}",
"env": {},
"envFile": "${workspaceFolder}/.env",
"debugOptions": [
"RedirectOutput"
]
}...

this is my user settings:
{
"python.pythonPath": "${workspaceRoot}/bin/python3",
}

is there something wrong with my config or what??? please help me.

@DonJayamanne
Copy link

@Mahdad-Baghani

should I use insiders build to solve this problem?

Yes please

@creepteks
Copy link

I Installed vscode insiders 1.20, still have the same problem.

@DonJayamanne
Copy link

@ericsnowcurrently please could you check whether you are able to replicate this using the insiders build?

@DonJayamanne
Copy link

Could be due to the different (or incorrect) names of the PATH variables in https://github.com/Microsoft/vscode-python/blob/master/src/client/common/platform/platformService.ts.

Could be related to #601

@DonJayamanne
Copy link

@Mahdad-Baghani you need to install the insiders build of the extension, please install it from here (instructions included). https://github.com/Microsoft/vscode-python/blob/master/CONTRIBUTING.md#insiders-build

@ericsnowcurrently
Copy link
Member

I verified that using 0.9.1 running import os; print(os.environ['PATH']) fails and using the insiders build it works.

@AlexandreOuellet
Copy link

I have both insider build 1.20 and insider extension for python, and I also get the same error :

import os; print(os.environ['PATH'])

Traceback (most recent call last):
File "/home/alexandre/gym/test.py", line 1, in
import os; print(os.environ['PATH'])
File "/home/alexandre/miniconda3/envs/openai-gym/lib/python3.6/os.py", line 669, in getitem
raise KeyError(key) from None
KeyError: 'PATH'

The one difference that made it work on my side though is if I launch with the option "Python: Terminal (integrated)", it works, but the usual "Python" launch setting doesn't work.

@bbcCorp
Copy link

bbcCorp commented Jan 30, 2018

I faced this issue with some other Python libraries. Till the new version of VSCode is released, I have added a .env file with

PATH=$PATH

That seems to solve the issue for me and I am able to use Python debugger.

@DonJayamanne
Copy link

@AlexandreOuellet @bbcCorp

  • What is your OS?
  • Please could you install the latest version of the insiders build of the extension from here (the new version has a couple of more fixes). (Downloads Python insiders build)

@bbcCorp

  • Please could you debugging using the following three debug configurations (please remove the .env file you created):
    • Python
    • Python Terminal (Integrated)
    • Python Terminal (External)

@AlexandreOuellet
Copy link

@DonJayamanne My os is Ubuntu 17.10. The updated python insiders build extension seems to have worked.

import os; print(os.environ['PATH'])
no longer creates the KeyError: 'PATH'

Thanks a lot!

@bbcCorp
Copy link

bbcCorp commented Feb 1, 2018

@DonJayamanne : I am using Mint Linux on Ubuntu 16.04.3 LTS (Xenial Xerus)

I removed the .env file and installed the insider build version. I can debug. So that resolves the problem for me. Thanks.

@Krishna1408
Copy link

Krishna1408 commented Mar 29, 2018

Hi Team,

I am using: Red Hat Enterprise Linux Server release 7.4 (Maipo)
Python Version: 3.6.3

I am also getting the same kind of error. I've set environment variables as: MP_IP . I am calling them using: mpip=os.environ["MP_IP"]

I am getting below error:

Traceback (most recent call last):
  File "orgAssociate/MpAssociation.py", line 9, in <module>
    mpip=os.environ["MP_IP"]
  File "/usr/local/lib/python3.6/os.py", line 669, in __getitem__
    raise KeyError(key) from None
KeyError: 'MP_IP'

I am running it using: sudo /usr/local/bin/python3.6 orgAssociate/Association.py

Can you please suggest what can be done for it?

@DonJayamanne
Copy link

DonJayamanne commented Mar 29, 2018

Please create a separate issue.

@lock lock bot locked as resolved and limited conversation to collaborators Jul 11, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-debugging bug Issue identified by VS Code Team member as probable bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.