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.

New "conda run" method of running python file results in errors

See original GitHub issue

Issue Type: Bug

Prior to update February 2022 1.65 you had to set: "python.terminal.activateEnvironment": true to make VSCode activate the selected environment with Conda and not to use the base one, now you need to set this option to false to be able to run the environment.

Step to Reproduce: 1- Use Conda as Python interpreter in VSCode 2- Set in VSCode a Python environment different from “base” 3- Set "python.terminal.activateEnvironment": true 4- If you have an open terminal, kill it 5- Run your code. At this step you will note that the terminal run conda activate <env_name> and then & conda run -n <env_name> --no-capture-output --live-stream python <full_filePath> and if the library you are importing is not in the “base” environment, you will get the error of missing module.

Error examples:

  • ERROR conda.cli.main_run:execute(33): Subprocess for 'conda run [' XXXXXXXXXX']' command failed. (See above for error)
  • Module not found etc.

Fix: set "python.terminal.activateEnvironment": false in your VSCode settings, reset terminal and it will run only & conda run -n <env_name> --no-capture-output --live-stream python <full_filePath>

Expected Results: Not sure if the expected behaviour is to set "python.terminal.activateEnvironment" to True or to False, at previous issues like https://github.com/microsoft/vscode-python/issues/9507, to set it False was a quick fix until an update was pushed. As a Conda user, this new behaviour would have saved me the trouble of setting "python.terminal.activateEnvironment" to True to use my environments (There is no warning about this so you require a bit of research to work with conda environments for the first time)

VS Code version: Code 1.65.0 (b5205cc8eb4fbaa726835538cd82372cc0222d43, 2022-03-02T11:12:08.962Z) OS version: Windows_NT x64 10.0.19043 Restricted Mode: No

System Info
Item Value
CPUs Intel® Core™ i5-4430 CPU @ 3.00GHz (4 x 3000)
GPU Status 2d_canvas: enabled
gpu_compositing: enabled
multiple_raster_threads: enabled_on
oop_rasterization: enabled
opengl: enabled_on
rasterization: enabled
skia_renderer: enabled_on
video_decode: enabled
vulkan: disabled_off
webgl: enabled
webgl2: enabled
Load (avg) undefined
Memory (System) 15.68GB (8.00GB free)
Process Argv –crash-reporter-id 352ea43a-dc87-43d8-b0c8-257406ae7a14
Screen Reader no
VM 0%
Extensions (7)
Extension Author (truncated) Version
gitlens eam 12.0.1
gitkraken-authentication git 1.0.3
python ms- 2022.2.1924087327
vscode-pylance ms- 2022.3.0
jupyter ms- 2022.2.1020642448
jupyter-keymap ms- 1.0.0
jupyter-renderers ms- 1.0.6
A/B Experiments
vsliv368cf:30146710
vsreu685:30147344
python383:30185418
vspor879:30202332
vspor708:30202333
vspor363:30204092
pythonvspyl392:30443607
pythontb:30283811
pythonptprofiler:30281270
vshan820:30294714
vstes263:30335439
vscoreces:30445986
pythondataviewer:30285071
vscod805:30301674
pythonvspyt200:30340761
binariesv615:30325510
bridge0708:30335490
bridge0723:30353136
vsaa593:30376534
vsc1dst:30438360
pythonvs932:30410667
wslgetstarted:30433507
vsclayoutctrc:30437038
vsrem710cf:30416617
vscop841cf:30447410
dsvsc008:30440022
pythonvsnew555:30442236
vsbas813:30436447
vscscmwlcmt:30438805
vscgsvid2:30447481
helix:30440343
vsnot107cf:30443615

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:11
  • Comments:18

github_iconTop GitHub Comments

3reactions
fsjwlfcommented, Mar 5, 2022

I found the same problem, and I wonder how can I run my python code… Now I pressed “conda activate xxx” and “python xxx.py” manually.

1reaction
karrtikrcommented, Mar 21, 2022

To verify, ensure conda run is not being used when a python file is run using the play icon on the top right.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Not able to run python file from conda environment
Using /bin/python3 is using the system-level Python, not the one in the environment. Instead, use plain " python " and let the PATH...
Read more >
Troubleshooting
The fix is to use the ./bin/conda executable in the conda git repository to force reinstall conda. That is, run ./bin/conda install -f...
Read more >
Run Python scripts in Power BI Desktop
Run Python scripts directly in Power BI Desktop and import the resulting datasets into a Power BI Desktop data model.
Read more >
Python on Windows FAQ
Contents: Python on Windows FAQ- How do I run a Python program under Windows?, How do I make Python scripts executable?, Why does...
Read more >
How can I run a python script using Anaconda from ...
1. Not really, anaconda tries to make a Python that is independent of the Python installed on the OS. · just type the...
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