Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
PythonPath file
#1
I am a beginning python programmer. My computer is running Linux Mint 17.3. I am using IDLE as the development environment. My question is simple. I know how to set a Pythonpath temporarily for a session. I want to include one or two directories in the path permanently. I also understand I can do that by appending the directories to the path file because it is a list. My problem is that I cannot find the file and I have searched with a number of extensions. If someone can tell me where I should start to look I would be very grateful.

Thanks.
likes this post
Reply
#2
PYTHONPATH is an environment variable.  In linux, those are stored in either .bash or .bash_profile or .bashrc in your home directory (/home/your_user_name).  If you're using a file browser, some of them hide files that start with ".", as those are normally "hidden" files.  If you open a console and navigate there ("cd ~"), you can see all files, including hidden ones, with "ls -a".  You can then edit that file using a text editor like nano "nano .bash".

What you add to that file will look similar to the following:

export PYTHONPATH="${PYTHONPATH}:/my/other/path"
Reply
#3
Do you want to programatically add these unknown directories to your path, or do you just want to find and add them on your system?
Reply
#4
Thanks for the replies. I will look for the file as suggested in the first post. As to second response. I would like to know how to add them programatically but my original question was to modify the file on my system so I could store all my scripts/programs in one place that is not defined with the python install. That is my current goal.

Thanks for the quick response.
Reply
#5
OK, I did look through my home directory and looked into all the text files, including hidden ones, and I could not find a file with path contents. Is there a second location where the file may be?
Reply
#6
Yes, but you shouldn't change the system files. That's why the code I posted starts with 'PYTHONPATH="${PYTHONPATH}'... you just add your stuff to whatever the path happens to already be. You don't want to actually change it, because then your computer would start behaving... badly.
Reply
#7
OK, I'll give it a shot. I misunderstood the reason for the command.
Thanks.
Reply
#8
@JohnRLaw

It is recommended to create a VENV, a Virtual Environment, when using Python. The professionals here make a new VENV for every project they get, I believe. The reason is, some modules have functions or classes of the same name, or different versions of the same module, which may interfere with each other.

Here is a link to how to make a VENV from realpython, a very good reference webpage.

Basically do this:

You have Python installed on your Linux Mint machine.

Make a folder to hold your VENV, or VENVs, (you can have as many as you like), call it whatever you like: My_Pythons perhaps? In bash, cd to that folder:

Quote:cd My_Pythons

Use this command in a bash terminal to create your virtual environment called GPE. (any name will do). This will install Python in a closed environment.

Quote:python3 -m venv --system-site-packages GPE

Now just type:

Quote:source GPE/bin/activate

And to start Idle:

Quote:python3 -m idlelib.idle

After that, whenever you want to start Python in your virtual environment, run this command in bash. (When you open bash, you will first be in your home folder)

Quote:cd My_Pythons && source GPE/bin/activate && python -m idlelib.idle

I had fun recently, because I could not start Idle. After a while I discovered Idle was not installed with my Python3.12, had to install it first.

Once you have your VENV up and running, you have all the Python builtins already there.

If you have run

Quote:source GPE/bin/activate

you will see the bash command line like this:

Quote:(GPE) pedro@pedro-MSI:~/My_Pythons$

From the above, install other Python modules you want like this:

Quote:(GPE) pedro@pedro-MSI:~/My_Pythons$ pip install module-name

The module will only be installed in your VENV, not system wide.

And when you are finished, don't forget to deactivate:

Quote:(GPE) pedro@pedro-MSI:~/My_Pythons$deactivate

to close your session.

You can also install different versions of Python in different VENVs.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  How to set PYTHONPATH in Visual Studio Code? aupres 5 20,425 Aug-15-2023, 03:51 PM
Last Post: snippsat
  the exe file by generated by pyinstaller ,can't get the PYTHONPATH roger2020 11 12,095 Jan-14-2020, 11:07 AM
Last Post: roger2020
  setting pythonpath variable in environment variables saisankalpj 3 5,196 Dec-05-2018, 10:33 PM
Last Post: Gribouillis
  Interpreter does not consider PYTHONPATH environment variable VegetaSSJ5 2 5,593 Aug-04-2017, 07:03 AM
Last Post: VegetaSSJ5

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020