Rocksolid Light

Welcome to RetroBBS

mail  files  register  newsreader  groups  login

Message-ID:  

Trespassers will be shot. Survivors will be prosecuted.


devel / comp.lang.python / Re: NameError: name '__version__' is not defined

SubjectAuthor
* NameError: name '__version__' is not definedLoris Bennett
+* Re: NameError: name '__version__' is not definedLoris Bennett
|`- Re: NameError: name '__version__' is not definedLoris Bennett
`- Re: NameError: name '__version__' is not definedDieter Maurer

1
NameError: name '__version__' is not defined

<87cyx04j77.fsf@zedat.fu-berlin.de>

  copy mid

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

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!not-for-mail
From: loris.bennett@fu-berlin.de (Loris Bennett)
Newsgroups: comp.lang.python
Subject: NameError: name '__version__' is not defined
Date: Fri, 27 Oct 2023 09:29:16 +0200
Organization: ZEDAT, Freie Universität Berlin
Lines: 47
Message-ID: <87cyx04j77.fsf@zedat.fu-berlin.de>
Mime-Version: 1.0
Content-Type: text/plain
X-Trace: news.uni-berlin.de a1cCVGFsHqflq9VT11O8tgkW8Hmx1czqbTX8qL+5q3LZNK
Cancel-Lock: sha1:TNx54TjVvOFRjXAC15nyHvtUuTA= sha1:T7YwOxKDL9avcI3Jias2yzVV7Sc= sha256:KdpPfBgiVcsA90Ztex94nKtbPSpxpsinDiO+s0Q5iNc=
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.2 (gnu/linux)
 by: Loris Bennett - Fri, 27 Oct 2023 07:29 UTC

Hi,

I have two applications. One uses the system version of Python, which
is 3.6.8, whereas the other uses Python 3.10.8 installed in a non-system
path. For both applications I am using poetry with a pyproject.toml
file which contains the version information and __init__.py at the root
which contains

try:
import importlib.metadata as importlib_metadata
except ModuleNotFoundError:
import importlib_metadata

__version__ = importlib_metadata.version(__name__)
For the application with the system Python this mechanism works, but for
the non-system Python I get the error:
NameError: name '__version__' is not defined

For the 3.6 application I have

PYTHONPATH=/nfs/local/lib/python3.6/site-packages
PYTHONUSERBASE=/nfs/local
PYTHON_VERSION=3.6
PYTHON_VIRTUALENV=

and for the 3.10 application I have

PYTHONPATH=/nfs/easybuild/software/Python/3.10.8-GCCcore-12.2.0/easybuild/python:/nfs/local/lib/python3.10/site-packages
PYTHONUSERBASE=/nfs/local
PYTHON_VERSION=3.10
PYTHON_VIRTUALENV=

The applications are installed in /nfs/local/lib/python3.6/site-packages
and /nfs/local/lib/python3.10/site-packages, respectively.

Can anyone see where this is going wrong? I thought it should be
enough that the packages with the metadata is available via PYTHONPATH,
but this seems not to be sufficient. So I must be overseeing something.

Cheers,

Loris

--
This signature is currently under constuction.

Re: NameError: name '__version__' is not defined

<8734xw4f90.fsf@zedat.fu-berlin.de>

  copy mid

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

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!news.nntp4.net!nntp.terraraq.uk!nntp-feed.chiark.greenend.org.uk!ewrotcd!fu-berlin.de!uni-berlin.de!not-for-mail
From: loris.bennett@fu-berlin.de (Loris Bennett)
Newsgroups: comp.lang.python
Subject: Re: NameError: name '__version__' is not defined
Date: Fri, 27 Oct 2023 10:54:35 +0200
Organization: ZEDAT, Freie Universität Berlin
Lines: 85
Message-ID: <8734xw4f90.fsf@zedat.fu-berlin.de>
References: <87cyx04j77.fsf@zedat.fu-berlin.de>
Mime-Version: 1.0
Content-Type: text/plain
X-Trace: news.uni-berlin.de ce6VBbvG6vsyjI3DJ/G9rAO3KDNEbBr1MONR5aSpxHMz9u
Cancel-Lock: sha1:hWPGFwJxFa/plk7cKNNdY2nD/1M= sha1:g2EFi5ACOIKqTgUli3pG2X6+WQk= sha256:ANPDOuJtMdMgEzC4or+EDUNwoTJqdQ3AAJSIpdjRW9Y=
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.2 (gnu/linux)
 by: Loris Bennett - Fri, 27 Oct 2023 08:54 UTC

"Loris Bennett" <loris.bennett@fu-berlin.de> writes:

> Hi,
>
> I have two applications. One uses the system version of Python, which
> is 3.6.8, whereas the other uses Python 3.10.8 installed in a non-system
> path. For both applications I am using poetry with a pyproject.toml
> file which contains the version information and __init__.py at the root
> which contains
>
> try:
> import importlib.metadata as importlib_metadata
> except ModuleNotFoundError:
> import importlib_metadata
>
> __version__ = importlib_metadata.version(__name__)
>
> For the application with the system Python this mechanism works, but for
> the non-system Python I get the error:
>
> NameError: name '__version__' is not defined
>
> For the 3.6 application I have
>
> PYTHONPATH=/nfs/local/lib/python3.6/site-packages
> PYTHONUSERBASE=/nfs/local
> PYTHON_VERSION=3.6
> PYTHON_VIRTUALENV=
>
> and for the 3.10 application I have
>
> PYTHONPATH=/nfs/easybuild/software/Python/3.10.8-GCCcore-12.2.0/easybuild/python:/nfs/local/lib/python3.10/site-packages
> PYTHONUSERBASE=/nfs/local
> PYTHON_VERSION=3.10
> PYTHON_VIRTUALENV=
>
> The applications are installed in /nfs/local/lib/python3.6/site-packages
> and /nfs/local/lib/python3.10/site-packages, respectively.
>
> Can anyone see where this is going wrong? I thought it should be
> enough that the packages with the metadata is available via PYTHONPATH,
> but this seems not to be sufficient. So I must be overseeing something.

If in the 3.10 application I add

print(f"__init__ Version: {__version__}")

to __init__.py the correct version is printed. So the problem is that
the variable is not available at the point I am trying access it. The
relevant code (a far as I can tell) in main.py looks like this:

import typer

app = typer.Typer()

@app.callback()
def version_callback(value: bool):
if value:
typer.echo(f"Version: {__version__}")
raise typer.Exit()

@app.callback()
def common(
ctx: typer.Context,
version: bool = typer.Option(None, "--version",
help="Show version",
callback=version_callback),
):
pass

if __name__ == "__main__":

app()

This is the first time I have used typer, so it is more than likely that
I have made some mistakes.

Cheers,

Loris

--
This signature is currently under constuction.

Re: NameError: name '__version__' is not defined

<87y1fo2zi5.fsf@zedat.fu-berlin.de>

  copy mid

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

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!news.1d4.us!usenet.goja.nl.eu.org!weretis.net!feeder8.news.weretis.net!fu-berlin.de!uni-berlin.de!not-for-mail
From: loris.bennett@fu-berlin.de (Loris Bennett)
Newsgroups: comp.lang.python
Subject: Re: NameError: name '__version__' is not defined
Date: Fri, 27 Oct 2023 11:20:02 +0200
Organization: ZEDAT, Freie Universität Berlin
Lines: 100
Message-ID: <87y1fo2zi5.fsf@zedat.fu-berlin.de>
References: <87cyx04j77.fsf@zedat.fu-berlin.de>
<8734xw4f90.fsf@zedat.fu-berlin.de>
Mime-Version: 1.0
Content-Type: text/plain
X-Trace: news.uni-berlin.de JqeB5SF4VjofatClAnIbSg/Kv0EYq4Wx95M5B6JJ1vmBA5
Cancel-Lock: sha1:Q9LmoPIE+n4yPOZCH+HumsU5bko= sha1:T62328jfLQqYcxhzB1iqrahORKA= sha256:K2HkGUq/mthNwr2Mo7wtMeZR1wz95ObCgr8MRgTY2Q4=
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.2 (gnu/linux)
 by: Loris Bennett - Fri, 27 Oct 2023 09:20 UTC

"Loris Bennett" <loris.bennett@fu-berlin.de> writes:

> "Loris Bennett" <loris.bennett@fu-berlin.de> writes:
>
>> Hi,
>>
>> I have two applications. One uses the system version of Python, which
>> is 3.6.8, whereas the other uses Python 3.10.8 installed in a non-system
>> path. For both applications I am using poetry with a pyproject.toml
>> file which contains the version information and __init__.py at the root
>> which contains
>>
>> try:
>> import importlib.metadata as importlib_metadata
>> except ModuleNotFoundError:
>> import importlib_metadata
>>
>> __version__ = importlib_metadata.version(__name__)
>>
>> For the application with the system Python this mechanism works, but for
>> the non-system Python I get the error:
>>
>> NameError: name '__version__' is not defined
>>
>> For the 3.6 application I have
>>
>> PYTHONPATH=/nfs/local/lib/python3.6/site-packages
>> PYTHONUSERBASE=/nfs/local
>> PYTHON_VERSION=3.6
>> PYTHON_VIRTUALENV=
>>
>> and for the 3.10 application I have
>>
>> PYTHONPATH=/nfs/easybuild/software/Python/3.10.8-GCCcore-12.2.0/easybuild/python:/nfs/local/lib/python3.10/site-packages
>> PYTHONUSERBASE=/nfs/local
>> PYTHON_VERSION=3.10
>> PYTHON_VIRTUALENV=
>>
>> The applications are installed in /nfs/local/lib/python3.6/site-packages
>> and /nfs/local/lib/python3.10/site-packages, respectively.
>>
>> Can anyone see where this is going wrong? I thought it should be
>> enough that the packages with the metadata is available via PYTHONPATH,
>> but this seems not to be sufficient. So I must be overseeing something.
>
> If in the 3.10 application I add
>
> print(f"__init__ Version: {__version__}")
>
> to __init__.py the correct version is printed. So the problem is that
> the variable is not available at the point I am trying access it. The
> relevant code (a far as I can tell) in main.py looks like this:
>
> import typer
>
> app = typer.Typer()
>
>
> @app.callback()
> def version_callback(value: bool):
> if value:
> typer.echo(f"Version: {__version__}")
> raise typer.Exit()
>
>
> @app.callback()
> def common(
> ctx: typer.Context,
> version: bool = typer.Option(None, "--version",
> help="Show version",
> callback=version_callback),
> ):
> pass
>
> if __name__ == "__main__":
>
> app()
>
> This is the first time I have used typer, so it is more than likely that
> I have made some mistakes.

OK, I worked it out. Instead of

typer.echo(f"Version: {__version__}")

I need

typer.echo(f"Version: {mypackage.__version__}")

Thanks for the help :-)

Even if no-one replies, it still helps me to have to formulate the
problem for an audience of people who probably know more than I do.

Cheers,

Loris

--
This signature is currently under constuction.

Re: NameError: name '__version__' is not defined

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

  copy mid

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

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!rocksolid2!news.neodome.net!fu-berlin.de!uni-berlin.de!not-for-mail
From: dieter@handshake.de (Dieter Maurer)
Newsgroups: comp.lang.python
Subject: Re: NameError: name '__version__' is not defined
Date: Fri, 27 Oct 2023 20:33:15 +0200
Lines: 14
Message-ID: <mailman.98.1698431598.3828.python-list@python.org>
References: <87cyx04j77.fsf@zedat.fu-berlin.de>
<25916.619.96240.943905@ixdm.fritz.box>
Mime-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
X-Trace: news.uni-berlin.de ZZ+4DxQLMcg0iU6H7KHurQRJ1/bm6cqUwuO/BlyD3nzQ==
Cancel-Lock: sha1:pt+1jOng/JwFo+o2DWcU1HlUZ1A= sha256:1CXI8VEZ376UvVjA+NB0sEn1PKUcm2aslajCIo1HhUo=
Return-Path: <dieter@handshake.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.008
X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'traceback': 0.04;
'error:': 0.05; 'subject:name': 0.07; 'cc:addr:python-list': 0.09;
'mechanism': 0.09; 'skip:` 10': 0.09; 'subject:not': 0.09; 'cc:no
real name:2**0': 0.14; 'bennett': 0.16; 'problem': 0.16; 'python':
0.16; 'cc:addr:python.org': 0.20; 'exception': 0.22; 'code': 0.23;
'received:de': 0.23; 'cannot': 0.25; 'cc:2**0': 0.25; 'context':
0.32; 'resolve': 0.32; 'but': 0.32; 'header:In-Reply-To:1': 0.34;
"skip:' 10": 0.37; 'wrote': 0.39; 'your': 0.64; 'look': 0.65;
'header:Received:6': 0.67; 'led': 0.81; '(such': 0.84;
'exceptions': 0.84; 'received:88': 0.84
In-Reply-To: <87cyx04j77.fsf@zedat.fu-berlin.de>
X-Mailer: VM 8.0.12-devo-585 under 21.4 (patch 24) "Standard C" XEmacs Lucid
(x86_64-linux-gnu)
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: <25916.619.96240.943905@ixdm.fritz.box>
X-Mailman-Original-References: <87cyx04j77.fsf@zedat.fu-berlin.de>
 by: Dieter Maurer - Fri, 27 Oct 2023 18:33 UTC

Loris Bennett wrote at 2023-10-27 09:29 +0200:
> ...
>For the application with the system Python this mechanism works, but for
>the non-system Python I get the error:
>
> NameError: name '__version__' is not defined

If you get exceptions (they usually end in `Error` (such as `NameError`)),
look at the traceback. The traceback informs you about
the calling context that led to the exception, espeically where
in the code the exception occurred.

If you cannot resolve the problem at your own,
include the traceback in your call for assistence.


devel / comp.lang.python / Re: NameError: name '__version__' is not defined

1
server_pubkey.txt

rocksolid light 0.9.81
clearnet tor