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

"Run Python File in Terminal" command fails due to using "conda run" #9433

Closed
mind6 opened this issue Jan 8, 2020 · 9 comments
Closed

"Run Python File in Terminal" command fails due to using "conda run" #9433

mind6 opened this issue Jan 8, 2020 · 9 comments
Assignees
Labels
bug Issue identified by VS Code Team member as probable bug

Comments

@mind6
Copy link

mind6 commented Jan 8, 2020

Environment data

Version: 1.41.1 (user setup)
Commit: 26076a4de974ead31f97692a0d32f90d735645c0
Date: 2019-12-18T14:58:56.166Z
Electron: 6.1.5
Chrome: 76.0.3809.146
Node.js: 12.4.0
V8: 7.6.303.31-electron.0
OS: Windows_NT x64 10.0.18363

I'm using Conda environments, conda version 4.8.0

Expected behaviour

When I invoke the "Run Python File in Terminal" command it should call "python.exe" in the activated environment.

Actual behaviour

The command uses the experimental feature "conda run --name=environment". This feature doesn't work yet on my machine. It always invokes the base environment rather than the selected project environment.

Steps to reproduce:

  1. create a new anaconda environment with a different python version from base environment
  2. select the new environment
  3. make sure all terminal sessions are closed
  4. run the following file: (resulting in creation of a new terminal window)
    import sys
    print(sys.version)

It will print the python version of the base environment.

2020-01-08_090522

@mind6 mind6 added triage-needed Needs assignment to the proper sub-team bug Issue identified by VS Code Team member as probable bug labels Jan 8, 2020
@brettcannon
Copy link
Member

I can't reproduce this with conda 4.7.12:

(base) C:\Users\...\Desktop>conda --version
conda 4.7.12

(base) C:\Users\...\Desktop>python --version
Python 3.7.4

(base) C:\Users\brcan\Desktop>conda create --name py38env python=3.8
...

(base) C:\Users\...\Desktop>conda run --name py38env python --version
Python 3.8.0

(base) C:\Users\...\Desktop>conda run --name py38env python "testing\some 3.7 bunk\a.py"
3.8.0 (default, Nov  6 2019, 16:00:02) [MSC v.1916 64 bit (AMD64)]

We can test to see if this is a bug specific to conda 4.8.1 and/or conda 4.8.0.

@mind6
Copy link
Author

mind6 commented Jan 8, 2020

Thanks for everyone's extremely quick responses!
It works on conda version 4.8.1 for me!

2020-01-08_093357

@mind6
Copy link
Author

mind6 commented Jan 8, 2020

On conda 4.8.1 it seems if your shell's activated environment is the base environment, the conda run -n ENV works. But if it's a different environment, it fails?
2020-01-08_094809

In VSCODE it happens to activate that different environment when it starts the shell, which is why conda run doesn't work. So I am able to manually work around the problem by activating the base environment and keeping the shell open, which the "run file" command will reuse, allowing "conda run" to work correctly.

@paw-lu
Copy link

paw-lu commented Jan 8, 2020

I'm having the same issue on both conda 4.8.0 and 4.8.1.

With script.py as

import sys

print(sys.path)
base ❯ conda run -n env_name python script.py 
['/Users/pcosta/miniconda3/envs/env_name/lib/python37.zip', '/Users/pcosta/miniconda3/envs/env_name/lib/python3.7', '/Users/pcosta/miniconda3/envs/env_name/lib/python3.7/lib-dynload', '/Users/pcosta/miniconda3/envs/env_name/lib/python3.7/site-packages']

base ❯ conda activate env_name

env_name ❯ python script.py
['/Users/pcosta/miniconda3/envs/env_name/lib/python37.zip', '/Users/pcosta/miniconda3/envs/env_name/lib/python3.7', '/Users/pcosta/miniconda3/envs/env_name/lib/python3.7/lib-dynload', '/Users/pcosta/miniconda3/envs/env_name/lib/python3.7/site-packages']

env_name ❯ conda run -n env_name python script.py
['/Users/pcosta/miniconda3/lib/python37.zip', '/Users/pcosta/miniconda3/lib/python3.7', '/Users/pcosta/miniconda3/lib/python3.7/lib-dynload', '/Users/pcosta/miniconda3/lib/python3.7/site-packages']

It seems that running conda run in the activated environment is not running Python in the environment specified.

Since VS Code activates the environment beforehand, then runs conda run when you click the run button, this causes the Python file to run in the wrong environment.

@karthiknadig karthiknadig self-assigned this Jan 8, 2020
@ghost ghost removed the triage-needed Needs assignment to the proper sub-team label Jan 8, 2020
@giahung24
Copy link

Hello, I am having issue with conda run -n too.
I can run my project code normally with (myenv) python command, but when using the "Run Python file in Terminal" (which is recently changed to conda run -n), my program seems to be halted and I see no printed message in the Integrated Terminal.

  • I'm using conda 4.7.8 on Linux mint.

@Christof23
Copy link

Christof23 commented Jan 9, 2020

@giahung24 if you set "extensions.autoUpdate": false in your settings.json and rollback the python extension to 2019.10.44104 then it fixes the issue.

@giahung24
Copy link

@giahung24 if you set "extensions.autoUpdate": false in your settings.json and rollback the python extension to 2019.10.44104 then it fixes the issue.

Thank you! It worked.

@karthiknadig
Copy link
Member

We are turning off conda run (for now ) and we will be doing a point release this week (see here for tracking on this #9490)

@paw-lu
Copy link

paw-lu commented Jan 13, 2020

Thanks for the update @karthiknadig!

@ghost ghost removed the triage label May 13, 2020
@lock lock bot locked as resolved and limited conversation to collaborators May 20, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Issue identified by VS Code Team member as probable bug
Projects
None yet
Development

No branches or pull requests

6 participants