Ask Your Question
2

How i use sage with pycharm in Ubuntu

asked 2017-09-07 15:53:08 +0200

this post is marked as community wiki

This post is a wiki. Anyone with karma >750 is welcome to improve it.

Can anyone please guide me how can i use sage on pycharm. I'm working on .ipynb files which have some sage command for plotting and mathematics, I want to use them on pycharm, if someone has idea then please share

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
2

answered 2017-09-08 03:28:41 +0200

dan_fulea gravatar image

updated 2017-09-08 03:35:09 +0200

(For my taste, eclipse is the better IDE for developing code. There can be very many projects in it... The following is taken from the recommended path to start sage inside eclipse. Well my taste is not changed right in this second, but give me some more...)

The beautiful dark themes and the light interface of pycharm, dedicated to python, made me give it one more serious try. I cannot remember if there are any special configuration steps i did some months ago, but pycharm+sage work today without special effort. Here are the steps just done to run a simple piece of code. This is not really ubuntu, but manjaro, which is not far away, the same should apply in most linux operating systems.

  1. Open a terminal and type sage -sh in it to get the sage environment. For me:

    [dan@k7 ~]$ which pycharm
    /usr/bin/pycharm
    [dan@k7 ~]$ sage -sh
    
    Starting subshell with Sage environment variables set.  Don't forget
    to exit when you are done.  Beware:
     * Do not do anything with other copies of Sage on your system.
     * Do not use this for installing Sage packages using "sage -i" or for
       running "make" at Sage's root directory.  These should be done
       outside the Sage shell.
    
    Bypassing shell configuration files...
    
    Note: SAGE_ROOT=/usr
    
  2. From this shell with the (sage-sh) prompter start pycharm:

    (sage-sh) dan@k7:~$ pycharm &
    [1] 30437
    
  3. Inside my pycharm there is now a test file named test012.py containing some lines of code from various areas of interest.

    from sage.all import *
    
    F = GF(2)
    print F
    
    R = PolynomialRing( F, name='X' )
    print R
    
    G = GL(3,F)
    print G.order()
    
    E = EllipticCurve( GF(2**53), [1,0,0,0,1] )
    print "ORDER %s for %s" % ( E.order().factor(), E )
    

    Only the first line is important, from sage.all import *. The rest is the test. Results in the pycharm console:

    /usr/bin/python2.7 /home/dan/PycharmProjects/test_01/test_012.py
    Finite Field of size 2
    Univariate Polynomial Ring in X over Finite Field of size 2 (using NTL)
    168
    ORDER 2^2 * 107 * 21044858204113 for Elliptic Curve defined by y^2 + x*y = x^3 + 1 over Finite Field in z53 of size 2^53
    
    Process finished with exit code 0
    

Hope it also works for you like a charm, enjoy!

edit flag offensive delete link more

Comments

@ dan_fulea Thank you for your reply. I downloaded the sagemath but but i'm unable to creat shell and this command is not working for me. sage -sh can you please explain how i can do this... to start sage i have to go inside sage folder and with ./sage, sage will work on terminal but not on pycharm. Please share your idea. Thank you.

siddiqui.902003 gravatar imagesiddiqui.902003 ( 2017-09-08 09:39:08 +0200 )edit

@ dan_fulea Thank you for your reply. I downloaded the sagemath but but i'm unable to creat shell and this command is not working for me. sage -sh can you please explain how i can do this... to start sage i have to go inside sage folder and with ./sage, sage will work on terminal but not on pycharm. Please share your idea. Thank you

siddiqui.902003 gravatar imagesiddiqui.902003 ( 2017-09-08 09:40:04 +0200 )edit

The steps are as follows:

  • Inside ubuntu start a terminal.
  • In the terminal type sage -sh - This command will set some environment variables, these are now valid for the terminal, and for the processes started from it. Make sure sage is in the path, else the "long path to sage" has to be used with the -sh option.
  • In the terminal we have now the needed sage settings. Type in it pycharm & . Again, pycharm should be installed and in the path.
  • pycharm opens, make a project file, inside a py-file, and the difference between a usual python run/debug and a sage run/debug is minimal, just make sure to put the line from sage.all import * at the beginning of the py-file containing sage code.

In case something is unclear, do not hesitate to ask!

dan_fulea gravatar imagedan_fulea ( 2017-09-08 20:23:47 +0200 )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: 2017-09-07 15:53:08 +0200

Seen: 3,443 times

Last updated: Sep 08 '17