-1

-> python3 --version = 3.10
-> python --version = 3.12

I usually run my code with python3 -m main, being on my conda virtual env and it works great. But when I want to run a notebook, I choose my interpreter (correct venv) but it runs the code with python (not python3) leading to "No module named ..."

What can I do ?

  • Downgrade python and python -m pip install for python instead of python3 ?
  • Try to configure vs code to use python3 -m ? This would be my prefered solution but I didn't find how to do it
4
  • Shift-Ctrl-P, Python: Select Interpreter Commented Oct 12, 2023 at 9:48
  • @treuss As explain in my post the interpreter for my venv uses python and not python3, thus having the wrong packages. But on a terminal I can run python3 from my venv Commented Oct 12, 2023 at 9:50
  • Then your question has nothing to do with VS Code as you have setup your virtual env incorrectly. Check the man-page of virtualenv on how to explicitly chose the python interpreter when setting up the env. Commented Oct 12, 2023 at 9:52
  • Can you explain why is my virtual env setup incorrectly ? I've always run my code without issues with python3 -m main in my env Commented Oct 12, 2023 at 10:01

1 Answer 1

-1

Found the solution.

where python3 => C:\Users\XXX\AppData\Local\Microsoft\WindowsApps\python3.exe
where python => C:\Users\XXX\anaconda3\envs\XXX\python.exe

So I always thought that when I was on my env and ran python3 it would use that env but it did not.

I need to find a way for conda to have python3 in the virtual envs or to stop using the python3 alias.

Sign up to request clarification or add additional context in comments.

3 Comments

The point of creating and activating a virtualenv is that python means the python that was used to create the virtualenv; any other command, including python3, has the same meaning that it would otherwise.
@KarlKnechtel thank you for your comment, so there is no reason to have a command named "python3" pointing to the python.exe in your virtual env, right ?
Er, I got some detail wrong there. Depending on your platform, the virtualenv may automatically set up those aliases, so as to pretend consistently that this is the only "available" Python while the virtualenv is active. However, it certainly isn't "necessary". But it seems like you may have been mistaken about virtualenvs more generally: each one is functionally a separate installation with its own collection of third-party libraries. I tried to give duplicate links for your question, but now I'm not actually sure what the question is, because i don't know what your misconception was.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.