Using Sage with PyCharm (all features)

87 views
Skip to first unread message

Rouven Dreimann

unread,
Nov 14, 2016, 7:40:53 AM11/14/16
to sage-support
Hello Everybody,

I want to use Sage with PyCharm, but I got some problems. First of all:
I start sage-shell with:

```sh
sage -sh

(sage-sh) rdreimann@C3XZ562:~$ ./pycharm-community-2016.2.3/bin/pycharm.sh
```

Now my problem:
Most of my code works fine then, but when I do something like this

```python
Zx.<x> = ZZ[]
```

I got an error:

```
   Zx.<x> = ZZ[];
       ^
SyntaxError: invalid syntax
```

When I use a worksheet in my "normal" notbook() everything's fine...
Any ideas, how I can have all the sage features in my pycharm?

Thanks

Dima Pasechnik

unread,
Nov 14, 2016, 8:56:25 AM11/14/16
to sage-support


On Monday, November 14, 2016 at 12:40:53 PM UTC, Rouven Dreimann wrote:
Hello Everybody,

I want to use Sage with PyCharm, but I got some problems. First of all:
I start sage-shell with:

```sh
sage -sh

(sage-sh) rdreimann@C3XZ562:~$ ./pycharm-community-2016.2.3/bin/pycharm.sh
```

Now my problem:
Most of my code works fine then, but when I do something like this

```python
Zx.<x> = ZZ[]
```

I got an error:

```
   Zx.<x> = ZZ[];
       ^
SyntaxError: invalid syntax
```

When I use a worksheet in my "normal" notbook() everything's fine...

Sage extends Python syntax by using a preparser; e.g.
 sage: preparse('Zx.<x> = ZZ[]')
"Zx = ZZ['x']; (x,) = Zx._first_ngens(1)"

and so everything at Sage prompt is automatically preparsed.
I don't know whether you can force this upon PyCharm,
but you can still use everything you need using Python syntax.
Note that the Sage library is written this way (no preparser),
so there are plenty of examples there;
also e.g. your example would be just

import sage.all
from sage.all import ZZ
Zx = ZZ['x']
(x,) = Zx._first_ngens(1)
# or just   (x,)=Zx.gens()
Reply all
Reply to author
Forward
0 new messages