skip to Main Content

I’ve downloaded the latest version of VS Code and I have the most updated version of Python but I just cannot understand why every time I type python --version into the terminal, it tells me I’m working with 2.7.16. Now I’ve found a way around this, I’ve been using an environment which allows me to get to version 3 , invoking it through typing source env/bin/activate into the terminal.

I really would like to know how to set the default environment to Python 3 and can’t figure out why it won’t do that even when it shows Python 3.11.3 64 bit in the bottom right hand corner. Even stranger is that when I’m supposedly working on Python version 2, it behaves the same way is 3 eg. If I request the type of unicode using u’ , it’ll give me a string back and not unicode. So here it behaves like Python 3 but when I want to download pip/ BeautifulSoup, it tells me my Python version is too old.

So I can just keep creating a Python 3 environment but I think I should really know how to set it as default.

Any help appreciated!!

Thanks

I tried to locate where Python 3 is through the terminal and then update the JSON user settings with this location but it didn’t make a difference.

2

Answers


  1. I think you are using Mac, even if you install Python 3, the Python 2 that comes with Mac is still intact.

    You can solve this problem by using a virtualenv.

    virtualenv --python=python3.11.3 .venv
    source .venv/bin/activate
    

    If you do not want to use a virtual environment and only want to display the Python version correctly, you can modify the alias in bash_profile.

    $ which python3
    /usr/local/bin/python3
    
    vi ~/.bash_profile  
    alias python='/usr/local/bin/python3'
    

    Then reload bash_profile

    source ~/.bash_profile
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search