Closed ercius closed 1 year ago
I think this ought to be using this function to get the version: https://github.com/OpenChemistry/stempy/blob/f410e4246d8b2cd2b540dd4a68bae812961385a2/python/stempy/utils.py#L15
It looks like it is working if I pip install
a wheel:
>>> import stempy
>>> stempy.get_version()
'3.2.1'
So it is not working in a development environment?
I get two different outputs when I use the CLI and a ipykernel in Jupyter. The package is installed from Pypi (3.2.1) in a conda environment. You can see that both methods (CLI and Jupyter) are pointing to the same site-packages.
In the CLI I get the correct version with the environment activated.
(stempy) ~$ python
Python 3.8.10 (default, Jun 4 2021, 15:09:15)
[GCC 7.5.0] :: Anaconda, Inc. on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import stempy
>>> stempy.get_version()
'3.2.1'
>>> stempy
<module 'stempy' from '/opt/tljh/user/envs/stempy/lib/python3.8/site-packages/stempy/__init__.py'>
In a Jupyter notebook using the same environment I get a different output
Using version
directly gives the same answer as Jupyter:
Im guessing that 0.1dev
is from some older install that has been removed and not fully cleaned up.
So, this method of getting the version can not (always?) be used when the package is installed in a conda environment and used with ipykernel.
This worked for me using the %%bash
magic to turn a cell into a bash shell:
%%bash
source activate stempy_dev
conda list stempy
output:
# packages in environment at /opt/tljh/user/envs/stempy_dev:
#
# Name Version Build Channel
stempy 3.2.2.dev12+g3601526 pypi_0 pypi
Hmm, I wasn't able to reproduce the issue, even with a python 3.8 conda environment where stempy was installed via pip. So it might be something specific to that conda environment. Maybe there are some leftover files lying around somewhere that it is finding.
I have a few ideas for things we can try. Can you run this code and see what it prints out?
from importlib.metadata import files
first_file = files("stempy")[0]
print(first_file.locate())
# I personally get this:
# /home/patrick/virtualenvs/stempy/lib/python3.8/site-packages/stempy-3.2.1.dist-info/INSTALLER
That might show us the file path importlib.metadata
is using. If it does, and it is a leftover install, you might be able to clean it up by removing the leftover files.
If that doesn't help, can you show me what you get when you run this code?
from pkg_resources import get_distribution
print(get_distribution("stempy").version)
Using importlib.metadata
is supposed to be preferred over using the older, slower pkg_resources
. But we can revert back to using it if we need to.
You are right. The notebook is in a folder with an old install or an attempt I made to build it locally.
from importlib.metadata import files
first_file = files("stempy")[0]
print(first_file.locate())
output: /home/jupyter-percius/stempy/.clang-format
Both ways of checking the version (importlib
and pkg_resources
) give the same output.
I moved the notebook file to my home directory and I get the correct output:
3.2.2.dev12+g3601526
Problem solved!
Im not sure how the stempy.version is supposed to get updated. But I think it always prints out the same thing.
Can this be fixed?