Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  newsreader  groups  login

Message-ID:  

I'm all for computer dating, but I wouldn't want one to marry my sister.


devel / comp.lang.python / Re: Incomplete sys.path with embeddable python (Windows)!?

SubjectAuthor
* Re: Incomplete sys.path with embeddable python (Windows)!?Ralf M.
`- Re: Incomplete sys.path with embeddable python (Windows)!?Greg Ewing

1
Re: Incomplete sys.path with embeddable python (Windows)!?

<mailman.153.1682201576.20750.python-list@python.org>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=23044&group=comp.lang.python#23044

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!rocksolid2!i2pn.org!weretis.net!feeder8.news.weretis.net!newsreader4.netcologne.de!news.netcologne.de!fu-berlin.de!uni-berlin.de!not-for-mail
From: Ral...@t-online.de (Ralf M.)
Newsgroups: comp.lang.python
Subject: Re: Incomplete sys.path with embeddable python (Windows)!?
Date: Sun, 23 Apr 2023 00:04:16 +0200
Lines: 57
Message-ID: <mailman.153.1682201576.20750.python-list@python.org>
References: <a90b360e-054a-d8c7-2275-6d197aec7040@t-online.de>
<ed2d59e2-20fc-deb8-8a55-a4aa39146d41@tompassin.net>
<3979254c-95fa-935f-e6a4-4756526f1171@t-online.de>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
X-Trace: news.uni-berlin.de i4OhfjDfRdFB6zuU5uPyAQa4dQGPEOAv2F4BZtPBrSYg==
Return-Path: <Ralf_M@t-online.de>
X-Original-To: python-list@python.org
Delivered-To: python-list@mail.python.org
Authentication-Results: mail.python.org; dkim=none reason="no signature";
dkim-adsp=none (unprotected policy); dkim-atps=neutral
X-Spam-Status: OK 0.003
X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'looks': 0.02;
'subject:python': 0.06; 'maintainers': 0.07; 'modules': 0.07;
'scripts.': 0.07; 'subject:Windows': 0.07; 'that?': 0.07; '*not*':
0.09; 'anyway,': 0.09; 'linux': 0.09; 'schrieb': 0.09; 'skip:_
20': 0.09; 'though.': 0.09; 'import': 0.15; '"import': 0.16;
'case).': 0.16; 'directories': 0.16; 'directory.': 0.16;
'directory.\xc2\xa0': 0.16; 'doable': 0.16; 'embeddable': 0.16;
'prepended': 0.16; 'resides': 0.16; 'restriction.': 0.16;
'script.': 0.16; 'think.': 0.16; 'url:ftp': 0.16; 'wrote:': 0.16;
'python': 0.16; 'pm,': 0.19; 'to:addr:python-list': 0.20;
'option': 0.20; 'code': 0.23; 'command': 0.23; 'installed': 0.23;
'lines': 0.23; 'run': 0.23; 'received:de': 0.23; 'python,': 0.25;
'tried': 0.26; 'local': 0.27; 'ideas': 0.28; 'wrong': 0.28;
'header:User-Agent:1': 0.30; 'module': 0.31; 'think': 0.32; 'but':
0.32; "i'll": 0.33; 'hold': 0.33; 'path': 0.33; 'script': 0.33;
'windows': 0.34; 'same': 0.34; "didn't": 0.34; 'package': 0.34;
'requires': 0.34; 'header:In-Reply-To:1': 0.34; 'track': 0.35;
'yes,': 0.35; 'following': 0.35; 'files': 0.36; 'errors': 0.36;
'source': 0.36; 'directory': 0.37; 'hard': 0.37;
'received:192.168': 0.37; 'file': 0.38; 'could': 0.38; 'put':
0.38; 'quite': 0.39; 'added': 0.39; 'otherwise': 0.39; 'use':
0.39; "couldn't": 0.40; 'hello,': 0.40; 'try': 0.40; 'in,': 0.60;
'search': 0.61; 'skip:o 10': 0.61; 'skip:\xc2 10': 0.62; 'gives':
0.62; 'here': 0.62; 'thus': 0.64; 'your': 0.64; 'came': 0.65;
'worked': 0.67; 'that,': 0.67; 'figures': 0.69; 'depending': 0.70;
'received:194': 0.70; 'little': 0.73; '8bit%:100': 0.76; 'finds':
0.76; '(e.g.,': 0.76; 'handles': 0.76; 'names,': 0.81; '(do':
0.84; '\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0': 0.84; 'line,': 0.93;
'mind,': 0.93
User-Agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:102.0) Gecko/20100101
Thunderbird/102.10.0
Content-Language: de-DE
In-Reply-To: <ed2d59e2-20fc-deb8-8a55-a4aa39146d41@tompassin.net>
X-TOI-EXPURGATEID: 150726::1682201062-DBFFCC10-66E13C83/0/0 CLEAN NORMAL
X-TOI-MSGID: 08705178-ebe6-4964-914e-d8c3988d5089
X-BeenThere: python-list@python.org
X-Mailman-Version: 2.1.39
Precedence: list
List-Id: General discussion list for the Python programming language
<python-list.python.org>
List-Unsubscribe: <https://mail.python.org/mailman/options/python-list>,
<mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive: <https://mail.python.org/pipermail/python-list/>
List-Post: <mailto:python-list@python.org>
List-Help: <mailto:python-list-request@python.org?subject=help>
List-Subscribe: <https://mail.python.org/mailman/listinfo/python-list>,
<mailto:python-list-request@python.org?subject=subscribe>
X-Mailman-Original-Message-ID: <3979254c-95fa-935f-e6a4-4756526f1171@t-online.de>
X-Mailman-Original-References: <a90b360e-054a-d8c7-2275-6d197aec7040@t-online.de>
<ed2d59e2-20fc-deb8-8a55-a4aa39146d41@tompassin.net>
 by: Ralf M. - Sat, 22 Apr 2023 22:04 UTC

Am 21.04.2023 um 18:07 schrieb Thomas Passin:
> On 4/20/2023 5:47 PM, Ralf M. wrote:
>> Hello,
>>
>> when I run a script with a "normally" installed python, the directory
>> the script resides in is automatically added as first element to
>> sys.path, so that "import my_local_module" finds my_local_module.py in
>> the directory of the script.
>>
>> However, when I run the same script with embeddable python ("Windows
>> embeddable package (64-bit)", download link
>> https://www.python.org/ftp/python/3.11.3/python-3.11.3-embed-amd64.zip) the script directory is *not* prepended to the path, thus "import my_local_module" gives an ImportError.
>>
>> I couldn't find an option to get the "normal" behaviour. Any ideas how
>> to do that?
>>
>> What I tried so far:
>> [...]
>> * I can add the following lines to every script:
>>      import sys
>>      script_path = __file__.rsplit("\\", 1)[0]
>>      if script_path not in sys.path:
>>          sys.path[0:0] = [script_path]
>>      import my_local_modul
>> [...]

Thank your for your hints.

> I haven't worked with embeddable python, but here are some possibilities
> that came to mind, depending on how your system works -
>
> 1. If your script is started from the command line, sys.argv[0] gives
> the path to the script;
I didn't think of sys.argv[0] to get at the path; this might be quite
useful, I'll try it out next week.

> You could use os.path.dirname() to get its
> directory.  This will end up the same place as your code fragment, but
> looks nicer and handles different path separators (e.g., Linux vs Windows);
Yes, but it requires another import and the embedded package is only
available for windows anyway, I think. I'll consider the idea, though.

> 2. You could write a little module that figures out the script's path
> and import that first in all your scripts.
>
> 3. If you know all the directories that your scripts will be in, you
> could add them all to a xx.pth file (do a search to make sure where to
> put .pth files for an embeddable case).
I thought about that, but for that to work all local modules across all
script locations must have unique names, otherwise import might get hold
of a module from the wrong directory. Certainly doable for a few
scripts, but might become a source of hard to track errors when the
number of scripts increases and later maintainers are not aware of the
naming restriction.

> [...}

Re: Incomplete sys.path with embeddable python (Windows)!?

<kaja3hFns33U1@mid.individual.net>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=23046&group=comp.lang.python#23046

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!newsreader4.netcologne.de!news.netcologne.de!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail
From: greg.ew...@canterbury.ac.nz (Greg Ewing)
Newsgroups: comp.lang.python
Subject: Re: Incomplete sys.path with embeddable python (Windows)!?
Date: Sun, 23 Apr 2023 11:49:03 +1200
Lines: 11
Message-ID: <kaja3hFns33U1@mid.individual.net>
References: <a90b360e-054a-d8c7-2275-6d197aec7040@t-online.de>
<ed2d59e2-20fc-deb8-8a55-a4aa39146d41@tompassin.net>
<3979254c-95fa-935f-e6a4-4756526f1171@t-online.de>
<mailman.153.1682201576.20750.python-list@python.org>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
X-Trace: individual.net uALnLBqmuvCMVshN4vmy+AcW3UxrUcC5iNXnSA5lg2oF380lrO
Cancel-Lock: sha1:j0NoZ3vtzo9wxPIut0Ip6panZUY=
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.12; rv:91.0)
Gecko/20100101 Thunderbird/91.3.2
Content-Language: en-US
In-Reply-To: <mailman.153.1682201576.20750.python-list@python.org>
 by: Greg Ewing - Sat, 22 Apr 2023 23:49 UTC

On 23/04/23 10:04 am, Ralf M. wrote:
> I thought about that, but for that to work all local modules across all
> script locations must have unique names, otherwise import might get hold
> of a module from the wrong directory.

You could put all the local modules belonging to a particular
script into a package named after the script, e.g. put the local
modules used by foo.py into a package called foolib.

--
Greg

1
server_pubkey.txt

rocksolid light 0.9.8
clearnet tor