Results 1 to 4 of 4

Thread: Python Versions Installed / Environment Path

Hybrid View

  1. #1
    Join Date
    Aug 2008
    Location
    Midwest US
    Beans
    104

    Python Versions Installed / Environment Path

    Newb questions, thanks for patience. Just starting with Python. My /etc directory has folders called:
    python
    python2.7
    python3
    python3.6
    Does this mean I have multiple versions installed? If so, how do I start one over the other?

    What do I have to set to get my interpreter to look in a particular directory for my *.py files?
    Thanks in advance.
    s

  2. #2
    Join Date
    Dec 2018
    Beans
    Hidden!

    Re: Python Versions Installed / Environment Path

    You have Python 2.7 and Python 3.6 installed. Since most people use Python3, You're probably going to use the following as the top line in your Python scripts:

    Code:
    #!/usr/bin/env python3
    If the script is for Python 2:

    Code:
    #!/usr/bin/env python2
    Not sure what you mean when you talk about setting up your interpreter. You can run python, python2 or python3 from the command line to open the interpreter. If you're using IDLE, I haven't used that in a while and don't use it much. It is common for people to have 2 versions of Python installed-- the latest version 2 available and the latest version 3 available.

  3. #3
    Join Date
    Aug 2008
    Location
    Midwest US
    Beans
    104

    Re: Python Versions Installed / Environment Path

    Thank freemedia2018!
    That helps resolve my questions about versions. What I meant by "setting up your interpreter" was how do I get it to look in the directory where my hello.py file resides? If I start the interpreter with "python hello.py" it tells me the file/directory does not exist. If I explicitly put in the entire path like "python /home/documents/python/hello.py" it runs. Is this a python interpreter setting or Linux environment variable that I have to change to get the interpreter to look in the directory where my file is?
    thanks again.
    s

  4. #4
    Join Date
    Dec 2018
    Beans
    Hidden!

    Re: Python Versions Installed / Environment Path

    Quote Originally Posted by SBFree View Post
    If I start the interpreter with "python hello.py" it tells me the file/directory does not exist.
    What you want to do is put that #!/usr/bin/env line i showed you as the top line in hello.py:

    Code:
    #!/usr/bin/env python2
    print "\x1b[1;33mhello, world!\x1b[m"
    Then set it to executable from the command line: (or your file manager)

    Code:
    chmod 755 hello.py
    Then copy it to a folder in your path:

    Code:
    echo $PATH
    That will show you the folders in your path.

    Alternatively... you could just say:

    Code:
    python /path/to/hello.py
    Where /path/to is the path for the folder that hello.py is in.
    Last edited by freemedia2018; March 15th, 2019 at 07:59 AM.

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •