Ask Your Question
1

I cannot import a python package that I can happily import using the same path within a python file run in IDLE.

asked 2021-11-10 19:25:59 +0100

anonymous user

Anonymous

I am new to SageMath and to PreTeXt that I am using it with. I cannot import a python package that I can happily import using the same path within a python file run in IDLE. If I remove the "import sys ... import ternary" lines the PreTeXt code runs fine and I get the sin curve. The ternary module is Marc Harper's installed from GitHub using pip. But the module is not found when I run with the 3 lines added (so I have not bothered to add code that uses the module yet!). (To keep code to a minimum in the <interactive> ... </interactive> part I would ideally like to be able to import python code). Can anyone put me on the right track please? (PSWith a Karma of 1 I had to remove the links at the top of the code indoor to have the question accepted)

<book xml:id="prog1" xml:lang="en-US"> <title>prog1</title> <chapter xml:id="my-chapter"> <interactive xml:id="simple-plot" platform="sage" width="100%" aspect="1:1"> <slate surface="sage"> plot(sin,(-5,5)) import sys sys.path.append("/usr/local/lib/python3.8/site-packages/") import ternary </slate> </interactive> </chapter> </book> </pretext>

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2021-11-11 11:05:42 +0100

slelievre gravatar image

updated 2021-11-12 12:17:00 +0100

Depending how you installed Sage, Sage's Python might not be the system Python.

Installing Python packages for one Python does not install them for the other one.

Beware also that there are two different packages on PyPI with similar names:

I think you want the second one.

To install the desired package for Sage's Python:

sage --pip install python-ternary

If you installed the other one, you may want to uninstall it:

sage --pip uninstall ternary
edit flag offensive delete link more

Comments

I have tried installing the package using this command. When I then type in sage import ternary' and enter I get back the prompt which seems to suggest the package has been installed. But actually there is aternary' function in sage already that does something quite different. The package I am trying to use plots dynamics on a triangle. I also asked the PreTeXt community and they pointed out that the package `ternary' that I am trying to import is not on the sage cell server that I am using, so I can't import it.

aubrey gravatar imageaubrey ( 2021-11-11 19:01:35 +0100 )edit

Both ternary and import ternary give errors in a fresh Sage installation; and at SageCell.

To request installing python-ternary at SageCell, write to the sage-cell mailing list:

slelievre gravatar imageslelievre ( 2021-11-12 12:15:54 +0100 )edit

Update: I asked on the sage-cell mailing list, and python-ternary is now installed on SageCell. See:

slelievre gravatar imageslelievre ( 2021-11-14 16:37:37 +0100 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2021-11-10 19:25:59 +0100

Seen: 310 times

Last updated: Nov 12 '21