Python Forum
Script File Failure-Path Error?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Script File Failure-Path Error?
#11
(Nov-28-2022, 10:09 AM)jerryf Wrote: Thanks again snippsat. So to confirm my understanding-when using cmd mode python does not appear to make any reference or use of Path and PYTHONPATH environment variables in searching for the script file, and so a full pathname must always be given unless starting from the directory containing the script file. Is that correct?
Yes.

Never do this.
C:\Users\jerry>hello_world.py
Now is the reliance on that file associations is correct and this can suddently change.
Use python,the you know that it will use Python 3.11.
C:\Users\jerry>python hello_world.py
Also when you later when need to configure editor/IDE you point to python.exe and what file associations is set to dosn't matter.
# A test to make sure with full path to python.exe
C:\Users>python -c "import sys; print(sys.executable)"
C:\python310\python.exe
You could also look into py,can by used to run any python version.
See that i have python 3.11,but still have python in OS Path that point to 3.10
# <py> will find newest one and don't care about what is OS path
G:\div_code
位 py -V
Python 3.11.0

G:\div_code
位 python -V
Python 3.10.5
I have some versions as you see馃憖
G:\div_code
位 py --list
 -V:3.11 *        Python 3.11 (64-bit)
 -V:3.10          Python 3.10 (64-bit)
 -V:3.9           Python 3.9 (64-bit)
 -V:3.8           Python 3.8 (64-bit)
 -V:3.7-32        Python 3.7 (32-bit)
 -V:3.6-32        Python 3.6 (32-bit)
 -V:3.5-32
 -V:3.4
 -V:2.7
 -V:2.1
 -V:ContinuumAnalytics/Anaconda39-64 Anaconda py39_4.9.2
 -V:ContinuumAnalytics/Anaconda37-64 Anaconda 4.7.12
 -V:ContinuumAnalytics/Anaconda36-32 Anaconda 4.3.14
Reply
#12
snappsat - thanks yet again for your response.
It was the file association vs python behaviour I was trying to understand, especially why the first option appeared to interact with the Windows Path environment but invoking python explicitly did not.

However, I can understand the logic of your suggestion to use the explicit [inline]python{/inline] method, but remembering to include the full pathname unless the file is in the current directory. Still seems a little odd but suspect this behaviour might be specific to the Windows implementation.

Am now going to investigate absolute and relative paths when using the interactive mode for building multi-module/package applications so that I can set up sensible folder structures for developing future projects.

Many thanks again for your guidance
Reply
#13
(Nov-29-2022, 02:45 PM)jerryf Wrote: Am now going to investigate absolute and relative paths when using the interactive mode for building multi-module/package applications so that I can set up sensible folder structures for developing future projects
Can give some tips,a advice for a better command line cmder
Also Shortcut to open Cmder in a chosen folder
Then can go from File Explorer direclty to any folder.

Also should now about Virtual Enviroment(build into Python) this i use always when build module/packages.
When use virtual enviroment will be isolated from all other Python version and get own sys.path
Example,and not using python command now would mess all this up.
# Make 
G:\div_code
位 python -m venv my_env

# Cd in
G:\div_code
位 cd my_env

# Activate
G:\div_code\my_env
位 G:\div_code\my_env\Scripts\activate

# Test path,see that it point only to this folder
(my_env) G:\div_code\my_env
位 python -c "import sys; print(sys.executable)"
G:\div_code\my_env\Scripts\python.exe

(my_env) G:\div_code\my_env
位 pip -V
pip 22.0.4 from G:\div_code\my_env\lib\site-packages\pip (python 3.10)
So if install something eg Requset it can not be confilcts as this is isolated.
(my_env) G:\div_code\my_env
位 pip install requests
Collecting requests
  Using cached requests-2.28.1-py3-none-any.whl (62 kB)
Collecting urllib3<1.27,>=1.21.1
  Downloading urllib3-1.26.13-py2.py3-none-any.whl (140 kB)
     ---------------------------------------- 140.6/140.6 KB 2.1 MB/s eta 0:00:00
Collecting charset-normalizer<3,>=2
  Using cached charset_normalizer-2.1.1-py3-none-any.whl (39 kB)
Collecting certifi>=2017.4.17
  Using cached certifi-2022.9.24-py3-none-any.whl (161 kB)
Collecting idna<4,>=2.5
  Using cached idna-3.4-py3-none-any.whl (61 kB)
Installing collected packages: urllib3, idna, charset-normalizer, certifi, requests
Successfully installed certifi-2022.9.24 charset-normalizer-2.1.1 idna-3.4 requests-2.28.1 urllib3-1.26.13

(my_env) G:\div_code\my_env
位 pip list
Package            Version
------------------ ---------
certifi            2022.9.24
charset-normalizer 2.1.1
idna               3.4
pip                22.0.4
requests           2.28.1
setuptools         58.1.0
urllib3            1.26.13
Reply
#14
Thanks for your latest comments.

I had already started looking at virtual environments in the python documentation so your feedback is timely.

I wasn't aware of cmdr so will take a look at that as well.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Failure to run source command middlestudent 2 689 Sep-22-2023, 01:21 PM
Last Post: buran
  File path by adding various variables Mishal0488 2 1,026 Apr-28-2023, 07:17 PM
Last Post: deanhystad
  Dickey Fuller failure Led_Zeppelin 4 2,609 Sep-15-2022, 09:07 PM
Last Post: Led_Zeppelin
  Script Path tfernandes 8 2,184 Jul-07-2022, 09:48 PM
Last Post: tfernandes
  Simple Python script, path not defined dubinaone 3 2,692 Nov-06-2021, 07:36 PM
Last Post: snippsat
  WebDriverException: Message: 'PATH TO CHROME DRIVER' executable needs to be in PATH Led_Zeppelin 1 2,203 Sep-09-2021, 01:25 PM
Last Post: Yoriz
  Assert failure jtcostel 1 1,638 Sep-03-2021, 05:28 PM
Last Post: buran
  Subprocess.Popen() not working when reading file path from csv file herwin 13 14,998 May-07-2021, 03:26 PM
Last Post: herwin
  Add file to sys.path permanently hcccs 5 8,368 Jan-31-2021, 11:26 AM
Last Post: hcccs
  Web Form to Python Script to Text File to zip file to web wfsteadman 1 2,133 Aug-09-2020, 02:12 PM
Last Post: snippsat

Forum Jump:

User Panel Messages

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