Python Forum
setting pythonpath variable in environment variables
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
setting pythonpath variable in environment variables
#2
Python imports modules. It means that when you write from one.sample1 import *, there is an importable module or package named one. Here are a few ways to achieve this:
  • Move the 'one' directory in 'two'. It will become importable in 'sample.py'
  • Put the directory containing 'one' on the python path by manipulating the python path through the PYTHONPATH environment variable or the files usercustomize.py or sitecustomize.py
  • Manipulate sys.path in 'sample.py' to make sure it contains the directory containing 'one'.
As you added an '__init__.py' file in 'parent', it may happen that you want 'one' or 'two' to be subpackages of module 'parent'. In that case you can put 'parent' on the python path instead of 'one' and just write from ..one.sample1 import * in 'sample.py' and invoke the script with the command python -m parent.two.sample.
Reply


Messages In This Thread
RE: setting pythonpath variable in environment variables - by Gribouillis - Dec-05-2018, 06:04 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Need help setting up trusted root ca in virtual environment dstempfley 0 111 May-31-2024, 03:14 PM
Last Post: dstempfley
  How to set PYTHONPATH in Visual Studio Code? aupres 5 4,916 Aug-15-2023, 03:51 PM
Last Post: snippsat
  Setting permanent user variables in Windows coder420 2 1,487 Jan-04-2022, 10:42 AM
Last Post: Larz60+
Question Calling on a Variable using other Variables jacknewport 4 2,089 Jul-23-2021, 04:18 PM
Last Post: jacknewport
  Create new variable dependent on two existing variables JoeOpdenaker 6 3,197 Oct-25-2020, 02:15 PM
Last Post: jefsummers
  Print variable values from a list of variables xnightwingx 3 2,721 Sep-01-2020, 02:56 PM
Last Post: deanhystad
  Help Setting Multiple Variables bzowk 0 1,653 Jul-18-2020, 06:59 PM
Last Post: bzowk
  the exe file by generated by pyinstaller ,can't get the PYTHONPATH roger2020 11 7,270 Jan-14-2020, 11:07 AM
Last Post: roger2020
  Trouble Setting a Variable True basing on an Imput VictorVictus 5 2,872 Aug-02-2019, 08:14 PM
Last Post: VictorVictus
  TESSDATA_PREFIX environment variable is set to your "tessdata" directory. rajeev1729 1 4,141 Jun-10-2019, 04:47 PM
Last Post: Gribouillis

Forum Jump:

User Panel Messages

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