acamposla
acamposla

Reputation: 11

Which Python - Versions, locations and uses

I have 2 python locations.

1st Location and Version:

~$ which python
/Users/alejandrocampos/opt/anaconda3/bin/python

Which corresponds to

Python 3.9.7 (default, Sep 16 2021, 08:50:36) 
[Clang 10.0.0 ] :: Anaconda, Inc. on darwin

2nd Location and Version:

~$ which python3
/opt/homebrew/bin/python3

Which corresponds to

Python 3.9.13 (main, May 24 2022, 21:13:51) 
[Clang 13.1.6 (clang-1316.0.21.2)] on darwin

I do not know exactly why and what implies... How can I know which one is being used in Sublime text, Vs Code or Jupyter notebook? How can I know which packets I have installed in each python version?

Thanks!

Upvotes: 1

Views: 514

Answers (1)

Rob G
Rob G

Reputation: 683

Question 1: How can I know which one is being used in Sublime text, Vs Code or Jupyter notebook?

Run the following code in any of those applications to get the Python version that it is using:

import sys
print(sys.version)

Question 2: How can I know which packets (sic) I have installed in each python version?

If you meant "packages":

import sys
import pkg_resources

print(sys.version)
packages = pkg_resources.working_set
packages_list = sorted(["%s==%s" % (i.key, i.version) for i in packages])
for p in packages_list:
    print(p)

Question 3: Even though you did not ask the question, "How do I set the Python version I want to use in Sublime text, VS Code or Jupyter Notebook?", here's some things you can try...

  • In Sublime Text:

    • Select Tools -> Build System -> New Build System.

    • Enter the following text:

      {
          "cmd": [<Location of your Python Interpreter>, "-u", "$file"],
          "file_regex": "^[ ]*File \"(...*?)\", line ([0-9]*)",
          "selector": "source.python",
      }
      
    • Save it as Python.3.9.x.sublime-build.

    • To run, select Tools -> Build System -> Python.3.9.x.

  • In Jupyter Notebook: Kernel -> Change kernel

  • In VS Code: In the Terminal, enter the Python executable path and the script path (e.g., /Users/alejandrocampos/opt/anaconda3/bin/python "/home/alejandrocampos/workspace/stack/version.py")

Upvotes: 2

Related Questions