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 3 years ago

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>

Preview: (hide)

1 Answer

Sort by » oldest newest most voted
1

answered 3 years ago

slelievre gravatar image

updated 3 years ago

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
Preview: (hide)
link

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 ( 3 years ago )

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 ( 3 years ago )

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

slelievre gravatar imageslelievre ( 3 years ago )

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: 3 years ago

Seen: 501 times

Last updated: Nov 12 '21