I want to shoot sightlines in TNG simulation, I installed trident for that using PIP install trident but after I do " import trident" in python environment I am getting an error
NameError Traceback (most recent call last)
/opt/conda/lib/python3.6/site-packages/unyt/_parsing.py in parse_unyt_expr(unit_expr)
92 unit_expr = parse_expr(
--->93 unit_expr, global_dict=global_dict, transformations=unit_text_transform
94 )
/opt/conda/lib/python3.6/site-packages/sympy/parsing/sympy_parser.py in parse_expr(s, local_dict, transformations, global_dict, evaluate)
893
-->894return eval_expr(code, local_dict, global_dict)
895
/opt/conda/lib/python3.6/site-packages/sympy/parsing/sympy_parser.py in eval_expr(code, local_dict, global_dict)
806 expr = eval(
-->807 code, global_dict, local_dict) # take local objects in preference808
<string> in <module>
NameError: name 'μSymbol'isnot defined
During handling of the above exception, another exception occurred:
UnitParseError Traceback (most recent call last)
<ipython-input-7-306c42f8c86a> in <module>
---->1import trident
/opt/conda/lib/python3.6/site-packages/trident/__init__.py in <module>
20# Must run import_check() before anything else is imported to avoid21# astropy error when importing trident in trident package directory
--->22 from trident.utilities import import_check
23 import_check()
24
/opt/conda/lib/python3.6/site-packages/trident/utilities.py in <module>
19import tempfile
20import shutil
--->21 from yt.funcs import \
22 get_pbar
23import numpy as np
/opt/conda/lib/python3.6/site-packages/yt/__init__.py in <module>
10 __version__ = "4.0.5"11
--->12import yt.units as units
13import yt.utilities.physical_constants as physical_constants
14 from yt.data_objects.api import (
/opt/conda/lib/python3.6/site-packages/yt/units/__init__.py in <module>
---->1 from unyt.array import (
2 loadtxt,
3 savetxt,
4 uconcatenate,
5 ucross,
/opt/conda/lib/python3.6/site-packages/unyt/__init__.py in <module>
73 from ._version import get_versions
74
--->75 from unyt import unit_symbols
76 from unyt import physical_constants
77
/opt/conda/lib/python3.6/site-packages/unyt/unit_symbols.py in <module>
31for _canonical_name, _alt_names in _name_alternatives.items():
32for _alt_name in_alt_names:
--->33 _namespace[_alt_name] = _Unit(_canonical_name, registry=_registry)
/opt/conda/lib/python3.6/site-packages/unyt/unit_object.py in __new__(cls, unit_expr, base_value, base_offset, dimensions, registry, latex_repr)
222return registry._unit_object_cache[unit_expr]
223 unit_cache_key = unit_expr
-->224 unit_expr = parse_unyt_expr(unit_expr)
225# Make sure we have an Expr at this point.226ifnot isinstance(unit_expr, Expr):
/opt/conda/lib/python3.6/site-packages/unyt/_parsing.py in parse_unyt_expr(unit_expr)
98 repr(e),
99 )
-->100 raise UnitParseError(msg)
101return unit_expr
UnitParseError: Unit expression 'µm' raised an error during parsing:
NameError("name 'μSymbol' is not defined",)
when I do this on my local PC it works fine but I can't do analysis on the local PC because of the large file size, I don't have that much space. Alternatively, I am using the fake spectra python library but Trident is more sophisticated so wanted to switch to it.
Dylan Nelson
21 Jul '23
If I had to guess, I would say that there is some version issue, maybe Python 3.6 is too old for this purpose. Ideally the package would tell you. I can't offer more than that, you could ask over at the Trident site whether someone has seen a similar error.
Hum Chand
21 Jul '23
Thanks for the reply, Is there any way to update Python in the remote jupyter lab interface, I guess it's a problem with the Sympy package which is not able to get updated to the latest version when I install Trident. Also I cannot upgrade sympy too .
Thanks for the help.
Dylan Nelson
21 Jul '23
You could try to set up a new python installation using e.g. miniconda, inside the Lab.
Ok so following your advice I was able to install Trident and it is working!
here is how to do it if anyone else is trying the same -
(The problem is the old version of Python so we need to install the newest version )
First install miniconda by running the following command in the terminal
mkdir -p ~/miniconda3
wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh -O ~/miniconda3/miniconda.sh
bash ~/miniconda3/miniconda.sh -b -u -p ~/miniconda3
rm -rf ~/miniconda3/miniconda.sh
~/miniconda3/bin/conda init bash
~/miniconda3/bin/conda init zsh
then you should have the latest version of Python installed to check- write Python -V and it should be Python 3.11.4or above.
now run the following command
pip install trident
after it is completed run python and inside the python environment write import trident (we are doing this to first time setup and configure trident) follow the instructions there and complete it.
now exit the python environment (Ctrl-D)
now to access the latest python in the notebook we need to make a kernel of that-
with this command it will create the kernel of the latest python - python -m ipykernel install --user
now create a new notebook and select Python 3, and now trident will work test it by import trident.
I want to shoot sightlines in TNG simulation, I installed trident for that using PIP install trident but after I do " import trident" in python environment I am getting an error
NameError Traceback (most recent call last) /opt/conda/lib/python3.6/site-packages/unyt/_parsing.py in parse_unyt_expr(unit_expr) 92 unit_expr = parse_expr( ---> 93 unit_expr, global_dict=global_dict, transformations=unit_text_transform 94 ) /opt/conda/lib/python3.6/site-packages/sympy/parsing/sympy_parser.py in parse_expr(s, local_dict, transformations, global_dict, evaluate) 893 --> 894 return eval_expr(code, local_dict, global_dict) 895 /opt/conda/lib/python3.6/site-packages/sympy/parsing/sympy_parser.py in eval_expr(code, local_dict, global_dict) 806 expr = eval( --> 807 code, global_dict, local_dict) # take local objects in preference 808 <string> in <module> NameError: name 'μSymbol' is not defined During handling of the above exception, another exception occurred: UnitParseError Traceback (most recent call last) <ipython-input-7-306c42f8c86a> in <module> ----> 1 import trident /opt/conda/lib/python3.6/site-packages/trident/__init__.py in <module> 20 # Must run import_check() before anything else is imported to avoid 21 # astropy error when importing trident in trident package directory ---> 22 from trident.utilities import import_check 23 import_check() 24 /opt/conda/lib/python3.6/site-packages/trident/utilities.py in <module> 19 import tempfile 20 import shutil ---> 21 from yt.funcs import \ 22 get_pbar 23 import numpy as np /opt/conda/lib/python3.6/site-packages/yt/__init__.py in <module> 10 __version__ = "4.0.5" 11 ---> 12 import yt.units as units 13 import yt.utilities.physical_constants as physical_constants 14 from yt.data_objects.api import ( /opt/conda/lib/python3.6/site-packages/yt/units/__init__.py in <module> ----> 1 from unyt.array import ( 2 loadtxt, 3 savetxt, 4 uconcatenate, 5 ucross, /opt/conda/lib/python3.6/site-packages/unyt/__init__.py in <module> 73 from ._version import get_versions 74 ---> 75 from unyt import unit_symbols 76 from unyt import physical_constants 77 /opt/conda/lib/python3.6/site-packages/unyt/unit_symbols.py in <module> 31 for _canonical_name, _alt_names in _name_alternatives.items(): 32 for _alt_name in _alt_names: ---> 33 _namespace[_alt_name] = _Unit(_canonical_name, registry=_registry) /opt/conda/lib/python3.6/site-packages/unyt/unit_object.py in __new__(cls, unit_expr, base_value, base_offset, dimensions, registry, latex_repr) 222 return registry._unit_object_cache[unit_expr] 223 unit_cache_key = unit_expr --> 224 unit_expr = parse_unyt_expr(unit_expr) 225 # Make sure we have an Expr at this point. 226 if not isinstance(unit_expr, Expr): /opt/conda/lib/python3.6/site-packages/unyt/_parsing.py in parse_unyt_expr(unit_expr) 98 repr(e), 99 ) --> 100 raise UnitParseError(msg) 101 return unit_expr UnitParseError: Unit expression 'µm' raised an error during parsing: NameError("name 'μSymbol' is not defined",)
when I do this on my local PC it works fine but I can't do analysis on the local PC because of the large file size, I don't have that much space. Alternatively, I am using the fake spectra python library but Trident is more sophisticated so wanted to switch to it.
If I had to guess, I would say that there is some version issue, maybe Python 3.6 is too old for this purpose. Ideally the package would tell you. I can't offer more than that, you could ask over at the Trident site whether someone has seen a similar error.
Thanks for the reply, Is there any way to update Python in the remote jupyter lab interface, I guess it's a problem with the Sympy package which is not able to get updated to the latest version when I install Trident. Also I cannot upgrade sympy too .
Thanks for the help.
You could try to set up a new python installation using e.g. miniconda, inside the Lab.
ok, thank you so much!
Ok so following your advice I was able to install Trident and it is working!
here is how to do it if anyone else is trying the same -
(The problem is the old version of Python so we need to install the newest version )
First install miniconda by running the following command in the terminal
mkdir -p ~/miniconda3 wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh -O ~/miniconda3/miniconda.sh bash ~/miniconda3/miniconda.sh -b -u -p ~/miniconda3 rm -rf ~/miniconda3/miniconda.sh ~/miniconda3/bin/conda init bash ~/miniconda3/bin/conda init zsh then you should have the latest version of Python installed to check- write Python -V and it should be Python 3.11.4 or above. now run the following command pip install trident
after it is completed run python and inside the python environment write import trident (we are doing this to first time setup and configure trident) follow the instructions there and complete it.
now exit the python environment (Ctrl-D)
now to access the latest python in the notebook we need to make a kernel of that-
with this command it will create the kernel of the latest
python - python -m ipykernel install --user
now create a new notebook and select Python 3, and now trident will work test it by import trident.