question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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

See original GitHub issue

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

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:9 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
Christof23commented, 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.

1reaction
paw-lucommented, 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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

python - "ERROR conda.cli.main_run:execute(33)
go to vscode Extensions market and search "python". right click on "Python"(published by microsoft) and click on "Install another version".
Read more >
Anaconda can't run Python script in command prompt
I just created a Python script, which is running fine in Spyder (I'm using Anaconda). When I try to run it now in...
Read more >
Run stand-alone scripts—ArcGIS Pro | Documentation
When I launch the Python Command Prompt window, why do I get an access is denied error? You cannot use conda commands to...
Read more >
Efficient Way to Activate Conda in VSCode - Medium
Option 2: Run “conda activate <env-name>” in terminal ... The second way is to have manual control of switching the conda environment in...
Read more >
How can I run a python script using Anaconda from the ...
Create required Anaconda environment conda create --name environmentName python=3 pandas numpy . Include all your dependencies at once while ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found