ASKSAGE: Sage Q&A Forum - Individual question feedhttp://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Wed, 20 Dec 2017 01:44:16 -0600Make PyCharm recognise the Sage python interpreterhttp://ask.sagemath.org/question/39742/make-pycharm-recognise-the-sage-python-interpreter/How do I configure PyCharm so I can edit and run Sage scripts?
When I tried selecting Sage's python in `C:\Program Files\SageMath 8.0\runtime\opt\sagemath-8.0\local\bin` PyCharm said 'cannot setup SDK'.
I am using SageMath 8 on Windows.
[Edit] Rephrased the question because it is partly solved (and is pretty difficult), asking new question for the remainder so it is more clear.Thu, 23 Nov 2017 08:08:17 -0600http://ask.sagemath.org/question/39742/make-pycharm-recognise-the-sage-python-interpreter/Comment by Iguananaut for <p>How do I configure PyCharm so I can edit and run Sage scripts?
When I tried selecting Sage's python in <code>C:\Program Files\SageMath 8.0\runtime\opt\sagemath-8.0\local\bin</code> PyCharm said 'cannot setup SDK'.</p>
<p>I am using SageMath 8 on Windows.</p>
<p>[Edit] Rephrased the question because it is partly solved (and is pretty difficult), asking new question for the remainder so it is more clear.</p>
http://ask.sagemath.org/question/39742/make-pycharm-recognise-the-sage-python-interpreter/?comment=40219#post-id-40219Alright, I was able to get at least something vaguely working. I'll write up my findings in an answer below.Mon, 18 Dec 2017 08:25:40 -0600http://ask.sagemath.org/question/39742/make-pycharm-recognise-the-sage-python-interpreter/?comment=40219#post-id-40219Comment by Iguananaut for <p>How do I configure PyCharm so I can edit and run Sage scripts?
When I tried selecting Sage's python in <code>C:\Program Files\SageMath 8.0\runtime\opt\sagemath-8.0\local\bin</code> PyCharm said 'cannot setup SDK'.</p>
<p>I am using SageMath 8 on Windows.</p>
<p>[Edit] Rephrased the question because it is partly solved (and is pretty difficult), asking new question for the remainder so it is more clear.</p>
http://ask.sagemath.org/question/39742/make-pycharm-recognise-the-sage-python-interpreter/?comment=40218#post-id-40218So far, I can at least get PyCharm somewhat working with the normal Cygwin Python interpreter (not Sage's yet). As I suspected it more or less works, though some configuration is necessary. I'll see if I can come up with some precise steps...Mon, 18 Dec 2017 07:48:51 -0600http://ask.sagemath.org/question/39742/make-pycharm-recognise-the-sage-python-interpreter/?comment=40218#post-id-40218Comment by Iguananaut for <p>How do I configure PyCharm so I can edit and run Sage scripts?
When I tried selecting Sage's python in <code>C:\Program Files\SageMath 8.0\runtime\opt\sagemath-8.0\local\bin</code> PyCharm said 'cannot setup SDK'.</p>
<p>I am using SageMath 8 on Windows.</p>
<p>[Edit] Rephrased the question because it is partly solved (and is pretty difficult), asking new question for the remainder so it is more clear.</p>
http://ask.sagemath.org/question/39742/make-pycharm-recognise-the-sage-python-interpreter/?comment=40217#post-id-40217I'm downloading and installing PyCharm for myself to see how far I can get, but I suspect it's a wild goose chase.Mon, 18 Dec 2017 07:22:33 -0600http://ask.sagemath.org/question/39742/make-pycharm-recognise-the-sage-python-interpreter/?comment=40217#post-id-40217Comment by Iguananaut for <p>How do I configure PyCharm so I can edit and run Sage scripts?
When I tried selecting Sage's python in <code>C:\Program Files\SageMath 8.0\runtime\opt\sagemath-8.0\local\bin</code> PyCharm said 'cannot setup SDK'.</p>
<p>I am using SageMath 8 on Windows.</p>
<p>[Edit] Rephrased the question because it is partly solved (and is pretty difficult), asking new question for the remainder so it is more clear.</p>
http://ask.sagemath.org/question/39742/make-pycharm-recognise-the-sage-python-interpreter/?comment=40215#post-id-40215`python.exe` is just a symbolic link (in Cygwin, which is something native Windows software doesn't know about). For starters you'd have to link to the real executable (the one in the same path) named `python2.7.exe`. Beyond that I don't know what other problems you might encounter though.Mon, 18 Dec 2017 07:14:51 -0600http://ask.sagemath.org/question/39742/make-pycharm-recognise-the-sage-python-interpreter/?comment=40215#post-id-40215Answer by Iguananaut for <p>How do I configure PyCharm so I can edit and run Sage scripts?
When I tried selecting Sage's python in <code>C:\Program Files\SageMath 8.0\runtime\opt\sagemath-8.0\local\bin</code> PyCharm said 'cannot setup SDK'.</p>
<p>I am using SageMath 8 on Windows.</p>
<p>[Edit] Rephrased the question because it is partly solved (and is pretty difficult), asking new question for the remainder so it is more clear.</p>
http://ask.sagemath.org/question/39742/make-pycharm-recognise-the-sage-python-interpreter/?answer=40220#post-id-40220The easiest way I found to go about this is to first set some permanent environment variables in your Windows environment. This can be done through a GUI in Windows, or via the cmd console. The console commands to set the necessary variables are:
setx Path "%Path%;C:\Program Files\SageMath 8.1\runtime\opt\sagemath-8.1\local\lib;C:\Program Files\SageMath 8.1\runtime\opt\sagemath-8.1\local\bin;C:\Program Files\SageMath 8.1\runtime\bin;C:\Program Files\SageMath 8.1\runtime\lib\lapack"
setx SAGE_ROOT /opt/sagemath-8.1
setx SAGE_LOCAL /opt/sagemath-8.1/local
setx DOT_SAGE /dot_sage
There are likely some others that should be set as well, but that was the bare minimum I found necessary to get Sage's Python interpreter working happily in PyCharm.
Then we need to correctly add Sage's Python interpreter to PyCharm's list of available interpreters. From the Welcome screen click on the little "Configure" gear and select "Settings" from the menu:
<img src="/upfiles/15136111488052484.png" />
In the settings page select "Project Intepreter"--this is where you can add additional interpreters for use across projects. You might have something different shown here for an already existing interpreter.
<img src="/upfiles/1513611334847733.png" />
Click the little gear icon in the top-right corner next to the drop-down list of available interpreters, and select "Add Local" from the menu. Then from the list of interpreter types, select "System Interpreter":
<img src="/upfiles/15136115038373408.png" />
Browse to the `python2.7.exe` executable under `C:\Program Files\SageMath 8.1\runtime\opt\sagemath-8.1\local\bin` (or you can just copy this path directly into the file browser):
<img src="/upfiles/15136115863681798.png" />
If you set up the correct environment variables, PyCharm should be able to successfully execute Sage's Python interpreter, and also populate the list of packages installed for that interpreter, and you'll see something like this:
<img src="/upfiles/15136116977327393.png" />
If you didn't set the `Path` environment variable correctly, then you'll get an error here (it might show "Permission error" or something like that). This is because Windows uses the `Path` environment variable to search for DLLs, and the correct paths need to be added in order to find the Cygwin DLL, among others. Otherwise the interpreter executable can't even start. If this does happen you can still proceed with adding that interpreter, but it won't work until you set the necessary environment variables.
Then when you start a new project, make sure to select the Sage Python as the default interpreter (you might be able to use it with a virtualenv as well but I haven't tried that--if you do make sure it inherits system site-packages, or else you don't get Sage, etc.) In general I don't think it's necessary:
<img src="/upfiles/15136118982381835.png" />
Finally, PyCharm also allows you to set environment variables to run the interpreter with on a per-project basis in a couple differentl places. You can configure environment variables in the "Run" configurations, and then again (separately, unfortunately) in the settings for the Console. This is actually what I did initially--I set `Path`, as well as `SAGE_ROOT` etc. just in PyCharm and that worked as well. But I found it simpler to just set the environment variables permanently in my environment. Then things "just worked".
Be aware that this is still just the normal Python interpreter, not the Sage interpreter, so it doesn't know how to run `.sage` files, nor is it aware of Sage syntax. But you should be able to `from sage.all import *` and use Sage objects in plain Python. To get that all working might be a little bit tricky, and I think should be tackled as a separate question.Mon, 18 Dec 2017 09:49:14 -0600http://ask.sagemath.org/question/39742/make-pycharm-recognise-the-sage-python-interpreter/?answer=40220#post-id-40220Comment by PHPirates for <p>The easiest way I found to go about this is to first set some permanent environment variables in your Windows environment. This can be done through a GUI in Windows, or via the cmd console. The console commands to set the necessary variables are:</p>
<pre><code>setx Path "%Path%;C:\Program Files\SageMath 8.1\runtime\opt\sagemath-8.1\local\lib;C:\Program Files\SageMath 8.1\runtime\opt\sagemath-8.1\local\bin;C:\Program Files\SageMath 8.1\runtime\bin;C:\Program Files\SageMath 8.1\runtime\lib\lapack"
setx SAGE_ROOT /opt/sagemath-8.1
setx SAGE_LOCAL /opt/sagemath-8.1/local
setx DOT_SAGE /dot_sage
</code></pre>
<p>There are likely some others that should be set as well, but that was the bare minimum I found necessary to get Sage's Python interpreter working happily in PyCharm.</p>
<p>Then we need to correctly add Sage's Python interpreter to PyCharm's list of available interpreters. From the Welcome screen click on the little "Configure" gear and select "Settings" from the menu:</p>
<p><img src="/upfiles/15136111488052484.png"></p>
<p>In the settings page select "Project Intepreter"--this is where you can add additional interpreters for use across projects. You might have something different shown here for an already existing interpreter.</p>
<p><img src="/upfiles/1513611334847733.png"></p>
<p>Click the little gear icon in the top-right corner next to the drop-down list of available interpreters, and select "Add Local" from the menu. Then from the list of interpreter types, select "System Interpreter":</p>
<p><img src="/upfiles/15136115038373408.png"></p>
<p>Browse to the <code>python2.7.exe</code> executable under <code>C:\Program Files\SageMath 8.1\runtime\opt\sagemath-8.1\local\bin</code> (or you can just copy this path directly into the file browser):</p>
<p><img src="/upfiles/15136115863681798.png"></p>
<p>If you set up the correct environment variables, PyCharm should be able to successfully execute Sage's Python interpreter, and also populate the list of packages installed for that interpreter, and you'll see something like this:</p>
<p><img src="/upfiles/15136116977327393.png"></p>
<p>If you didn't set the <code>Path</code> environment variable correctly, then you'll get an error here (it might show "Permission error" or something like that). This is because Windows uses the <code>Path</code> environment variable to search for DLLs, and the correct paths need to be added in order to find the Cygwin DLL, among others. Otherwise the interpreter executable can't even start. If this does happen you can still proceed with adding that interpreter, but it won't work until you set the necessary environment variables.</p>
<p>Then when you start a new project, make sure to select the Sage Python as the default interpreter (you might be able to use it with a virtualenv as well but I haven't tried that--if you do make sure it inherits system site-packages, or else you don't get Sage, etc.) In general I don't think it's necessary:</p>
<p><img src="/upfiles/15136118982381835.png"></p>
<p>Finally, PyCharm also allows you to set environment variables to run the interpreter with on a per-project basis in a couple differentl places. You can configure environment variables in the "Run" configurations, and then again (separately, unfortunately) in the settings for the Console. This is actually what I did initially--I set <code>Path</code>, as well as <code>SAGE_ROOT</code> etc. just in PyCharm and that worked as well. But I found it simpler to just set the environment variables permanently in my environment. Then things "just worked".</p>
<p>Be aware that this is still just the normal Python interpreter, not the Sage interpreter, so it doesn't know how to run <code>.sage</code> files, nor is it aware of Sage syntax. But you should be able to <code>from sage.all import *</code> and use Sage objects in plain Python. To get that all working might be a little bit tricky, and I think should be tackled as a separate question.</p>
http://ask.sagemath.org/question/39742/make-pycharm-recognise-the-sage-python-interpreter/?comment=40247#post-id-40247PyCharm now recognises the Sage python, thanks! Indeed, maybe this question should be about getting PyCharm to recognise the Sage python and the next question about the problems I encounter when actually trying to `from sage.all import *`.I will ask it soon!Wed, 20 Dec 2017 01:44:16 -0600http://ask.sagemath.org/question/39742/make-pycharm-recognise-the-sage-python-interpreter/?comment=40247#post-id-40247Answer by dan_fulea for <p>How do I configure PyCharm so I can edit and run Sage scripts?
When I tried selecting Sage's python in <code>C:\Program Files\SageMath 8.0\runtime\opt\sagemath-8.0\local\bin</code> PyCharm said 'cannot setup SDK'.</p>
<p>I am using SageMath 8 on Windows.</p>
<p>[Edit] Rephrased the question because it is partly solved (and is pretty difficult), asking new question for the remainder so it is more clear.</p>
http://ask.sagemath.org/question/39742/make-pycharm-recognise-the-sage-python-interpreter/?answer=39750#post-id-39750This is a linux machine answering. The "answer" is possibly not the solution, but i need space to insert information, a comment is not enough.
In [38750](https://ask.sagemath.org/question/38750/how-i-use-sage-with-pycharm-in-ubuntu/) the procedure was described for a linux machine. `sage -sh` sets all needed variables for the operating system. In my case:
(sage-sh) dan@f... :~$ printenv | fgrep SAGE
gives the list of all more or less needed variables. Among them the most important one is
SAGE_ROOT=/usr
The right corresponding value(s) should maybe be set for Windows.
Here is the list, well, i hesitated first to insert it, but soon we will see some of the variables again...
$ printenv | fgrep SAGE
SAGE_DOC_SRC=/usr/share/doc/sage
SAGE_ETC=/usr/etc
SAGE_SHARE=/usr/share
SAGE_NUM_THREADS_PARALLEL=4
SAGE_STARTUP_FILE=/home/dan/.sage//init.sage
SAGE_SPKG_INST=/usr/var/lib/sage/installed
SAGE_ORIG_PATH_SET=True
SAGE_SRC=/usr/share/sage/source
SAGE_DOC=/usr/share/doc/sage
SAGE_LOCAL=/usr
SAGE_ENV_SOURCED=4
SAGE_REPO_ANONYMOUS=git://trac.sagemath.org/sage.git
SAGE_DOC_MATHJAX=True
SAGE_ORIG_PATH=/home/dan/bin:/usr/local/sbin:/usr/local/bin:/usr/bin:/usr/lib/jvm/default/bin:/usr/bin/site_perl:/usr/bin/vendor_perl:/usr/bin/core_perl
SAGE_LOGS=/usr/logs/pkgs
SAGE_EXTCODE=/usr/share/sage/ext
SAGE_ROOT=/usr
SAGE64=no
SAGE_DISTFILES=/usr/upstream
SAGE_NUM_THREADS=1
DOT_SAGE=/home/dan/.sage/
SAGE_REPO_AUTHENTICATED=ssh://git@trac.sagemath.org:2222/sage.git
A first try to set sage up and running in Windows is to insure that the Windows Python27 interpreter (that must be somewhere, possibly in `C:\Python27`) is found from the command line (running `cmd.exe`) and that inside of the python dialog box offered something like `from sage.all import *` is working...
Let me show the difference in Linux first. In a terminal...
$ python2.7
Python 2.7.14 (default, Sep 20 2017, 02:02:23)
[GCC 7.2.0] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from sage.all import *
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python2.7/site-packages/sage/all.py", line 71, in <module>
from sage.env import SAGE_ROOT, SAGE_SRC, SAGE_DOC_SRC, SAGE_LOCAL, DOT_SAGE, SAGE_ENV
File "/usr/lib/python2.7/site-packages/sage/env.py", line 154, in <module>
SINGULAR_SO = SAGE_LOCAL+"/lib/libSingular."+extension
TypeError: unsupported operand type(s) for +: 'NoneType' and 'str'
>>>
Such information is hidden in the dark, when pycharm or an other IDE hits the issue.
The same after setting the right environment variables, using the simple `sage -sh` first:
$ 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
(sage-sh) dan@f...:~$ python2.7
Python 2.7.14 (default, Sep 20 2017, 02:02:23)
[GCC 7.2.0] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from sage.all import *
>>> F = GF(2017)
>>> print F.multiplicative_generator()
5
My blind answer is to make the above first run from the command line in Windows. Then start pycharm against the right windows environment variables. In pycharm, or an other IDE, **the python interpreter is still python27**, not sage. To run sage inside, one has to do the above, possibly having to declare the libraries somewhere. In pycharm, this may be done using Settings > **Project Structure** . But my pycharm works without such a declaration.
Note that there is no pre-processing. So i have to type with contorsions something like...
from sage.all import *
for p in primes( 10**20, 10**20 + 1000 ):
R = PolynomialRing( GF( p ), names='X' )
X = R.gens()[0]
if not (X**4 - 2).is_irreducible():
print ("...reducible polynom mod %s :: X^4-2 = %s -> next prime..."
% (p, factor( X**4 - 2 )))
continue
print "%s is OK" % p
break
in order to get the first prime $p$ for which $X^4-2$ is irreducible in $\mathbb F_p[X]$. I could run the above code in my pycharm project.
Good luck!
Thu, 23 Nov 2017 14:16:16 -0600http://ask.sagemath.org/question/39742/make-pycharm-recognise-the-sage-python-interpreter/?answer=39750#post-id-39750Comment by Iguananaut for <p>This is a linux machine answering. The "answer" is possibly not the solution, but i need space to insert information, a comment is not enough. </p>
<p>In <a href="https://ask.sagemath.org/question/38750/how-i-use-sage-with-pycharm-in-ubuntu/">38750</a> the procedure was described for a linux machine. <code>sage -sh</code> sets all needed variables for the operating system. In my case:</p>
<pre><code>(sage-sh) dan@f... :~$ printenv | fgrep SAGE
</code></pre>
<p>gives the list of all more or less needed variables. Among them the most important one is</p>
<pre><code>SAGE_ROOT=/usr
</code></pre>
<p>The right corresponding value(s) should maybe be set for Windows.
Here is the list, well, i hesitated first to insert it, but soon we will see some of the variables again...</p>
<pre><code>$ printenv | fgrep SAGE
SAGE_DOC_SRC=/usr/share/doc/sage
SAGE_ETC=/usr/etc
SAGE_SHARE=/usr/share
SAGE_NUM_THREADS_PARALLEL=4
SAGE_STARTUP_FILE=/home/dan/.sage//init.sage
SAGE_SPKG_INST=/usr/var/lib/sage/installed
SAGE_ORIG_PATH_SET=True
SAGE_SRC=/usr/share/sage/source
SAGE_DOC=/usr/share/doc/sage
SAGE_LOCAL=/usr
SAGE_ENV_SOURCED=4
SAGE_REPO_ANONYMOUS=git://trac.sagemath.org/sage.git
SAGE_DOC_MATHJAX=True
SAGE_ORIG_PATH=/home/dan/bin:/usr/local/sbin:/usr/local/bin:/usr/bin:/usr/lib/jvm/default/bin:/usr/bin/site_perl:/usr/bin/vendor_perl:/usr/bin/core_perl
SAGE_LOGS=/usr/logs/pkgs
SAGE_EXTCODE=/usr/share/sage/ext
SAGE_ROOT=/usr
SAGE64=no
SAGE_DISTFILES=/usr/upstream
SAGE_NUM_THREADS=1
DOT_SAGE=/home/dan/.sage/
SAGE_REPO_AUTHENTICATED=ssh://git@trac.sagemath.org:2222/sage.git
</code></pre>
<p>A first try to set sage up and running in Windows is to insure that the Windows Python27 interpreter (that must be somewhere, possibly in <code>C:\Python27</code>) is found from the command line (running <code>cmd.exe</code>) and that inside of the python dialog box offered something like <code>from sage.all import *</code> is working...</p>
<p>Let me show the difference in Linux first. In a terminal...</p>
<pre><code>$ python2.7
Python 2.7.14 (default, Sep 20 2017, 02:02:23)
[GCC 7.2.0] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from sage.all import *
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python2.7/site-packages/sage/all.py", line 71, in <module>
from sage.env import SAGE_ROOT, SAGE_SRC, SAGE_DOC_SRC, SAGE_LOCAL, DOT_SAGE, SAGE_ENV
File "/usr/lib/python2.7/site-packages/sage/env.py", line 154, in <module>
SINGULAR_SO = SAGE_LOCAL+"/lib/libSingular."+extension
TypeError: unsupported operand type(s) for +: 'NoneType' and 'str'
>>>
</code></pre>
<p>Such information is hidden in the dark, when pycharm or an other IDE hits the issue.</p>
<p>The same after setting the right environment variables, using the simple <code>sage -sh</code> first:</p>
<pre><code>$ 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
(sage-sh) dan@f...:~$ python2.7
Python 2.7.14 (default, Sep 20 2017, 02:02:23)
[GCC 7.2.0] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from sage.all import *
>>> F = GF(2017)
>>> print F.multiplicative_generator()
5
</code></pre>
<p>My blind answer is to make the above first run from the command line in Windows. Then start pycharm against the right windows environment variables. In pycharm, or an other IDE, <strong>the python interpreter is still python27</strong>, not sage. To run sage inside, one has to do the above, possibly having to declare the libraries somewhere. In pycharm, this may be done using Settings > <strong>Project Structure</strong> . But my pycharm works without such a declaration.</p>
<p>Note that there is no pre-processing. So i have to type with contorsions something like...</p>
<pre><code>from sage.all import *
for p in primes( 10**20, 10**20 + 1000 ):
R = PolynomialRing( GF( p ), names='X' )
X = R.gens()[0]
if not (X**4 - 2).is_irreducible():
print ("...reducible polynom mod %s :: X^4-2 = %s -> next prime..."
% (p, factor( X**4 - 2 )))
continue
print "%s is OK" % p
break
</code></pre>
<p>in order to get the first prime $p$ for which $X^4-2$ is irreducible in $\mathbb F_p[X]$. I could run the above code in my pycharm project.</p>
<p>Good luck!</p>
http://ask.sagemath.org/question/39742/make-pycharm-recognise-the-sage-python-interpreter/?comment=40216#post-id-40216All the stuff in these comments are misguided. Dan was on the right track at least that you'd need to set some of the environment variables set by `sage -sh`, but for the rest of this it looks like you're trying to use the Windows Python to run code in Sage which will never, ever work. You must use the Python interpreter executable in Sage, like you initially tried in the text of the question. However, as I commented above, you must provide the "real" executable `python2.7.exe`, not the symbolic link which only Cygwin understands. Further, I'm not sure if the Cygwin-based Python interpreter will work in PyCharm, but if it doesn't I would consider that a bit of a defect in PyCharm tbh.Mon, 18 Dec 2017 07:19:30 -0600http://ask.sagemath.org/question/39742/make-pycharm-recognise-the-sage-python-interpreter/?comment=40216#post-id-40216Comment by dan_fulea for <p>This is a linux machine answering. The "answer" is possibly not the solution, but i need space to insert information, a comment is not enough. </p>
<p>In <a href="https://ask.sagemath.org/question/38750/how-i-use-sage-with-pycharm-in-ubuntu/">38750</a> the procedure was described for a linux machine. <code>sage -sh</code> sets all needed variables for the operating system. In my case:</p>
<pre><code>(sage-sh) dan@f... :~$ printenv | fgrep SAGE
</code></pre>
<p>gives the list of all more or less needed variables. Among them the most important one is</p>
<pre><code>SAGE_ROOT=/usr
</code></pre>
<p>The right corresponding value(s) should maybe be set for Windows.
Here is the list, well, i hesitated first to insert it, but soon we will see some of the variables again...</p>
<pre><code>$ printenv | fgrep SAGE
SAGE_DOC_SRC=/usr/share/doc/sage
SAGE_ETC=/usr/etc
SAGE_SHARE=/usr/share
SAGE_NUM_THREADS_PARALLEL=4
SAGE_STARTUP_FILE=/home/dan/.sage//init.sage
SAGE_SPKG_INST=/usr/var/lib/sage/installed
SAGE_ORIG_PATH_SET=True
SAGE_SRC=/usr/share/sage/source
SAGE_DOC=/usr/share/doc/sage
SAGE_LOCAL=/usr
SAGE_ENV_SOURCED=4
SAGE_REPO_ANONYMOUS=git://trac.sagemath.org/sage.git
SAGE_DOC_MATHJAX=True
SAGE_ORIG_PATH=/home/dan/bin:/usr/local/sbin:/usr/local/bin:/usr/bin:/usr/lib/jvm/default/bin:/usr/bin/site_perl:/usr/bin/vendor_perl:/usr/bin/core_perl
SAGE_LOGS=/usr/logs/pkgs
SAGE_EXTCODE=/usr/share/sage/ext
SAGE_ROOT=/usr
SAGE64=no
SAGE_DISTFILES=/usr/upstream
SAGE_NUM_THREADS=1
DOT_SAGE=/home/dan/.sage/
SAGE_REPO_AUTHENTICATED=ssh://git@trac.sagemath.org:2222/sage.git
</code></pre>
<p>A first try to set sage up and running in Windows is to insure that the Windows Python27 interpreter (that must be somewhere, possibly in <code>C:\Python27</code>) is found from the command line (running <code>cmd.exe</code>) and that inside of the python dialog box offered something like <code>from sage.all import *</code> is working...</p>
<p>Let me show the difference in Linux first. In a terminal...</p>
<pre><code>$ python2.7
Python 2.7.14 (default, Sep 20 2017, 02:02:23)
[GCC 7.2.0] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from sage.all import *
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python2.7/site-packages/sage/all.py", line 71, in <module>
from sage.env import SAGE_ROOT, SAGE_SRC, SAGE_DOC_SRC, SAGE_LOCAL, DOT_SAGE, SAGE_ENV
File "/usr/lib/python2.7/site-packages/sage/env.py", line 154, in <module>
SINGULAR_SO = SAGE_LOCAL+"/lib/libSingular."+extension
TypeError: unsupported operand type(s) for +: 'NoneType' and 'str'
>>>
</code></pre>
<p>Such information is hidden in the dark, when pycharm or an other IDE hits the issue.</p>
<p>The same after setting the right environment variables, using the simple <code>sage -sh</code> first:</p>
<pre><code>$ 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
(sage-sh) dan@f...:~$ python2.7
Python 2.7.14 (default, Sep 20 2017, 02:02:23)
[GCC 7.2.0] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from sage.all import *
>>> F = GF(2017)
>>> print F.multiplicative_generator()
5
</code></pre>
<p>My blind answer is to make the above first run from the command line in Windows. Then start pycharm against the right windows environment variables. In pycharm, or an other IDE, <strong>the python interpreter is still python27</strong>, not sage. To run sage inside, one has to do the above, possibly having to declare the libraries somewhere. In pycharm, this may be done using Settings > <strong>Project Structure</strong> . But my pycharm works without such a declaration.</p>
<p>Note that there is no pre-processing. So i have to type with contorsions something like...</p>
<pre><code>from sage.all import *
for p in primes( 10**20, 10**20 + 1000 ):
R = PolynomialRing( GF( p ), names='X' )
X = R.gens()[0]
if not (X**4 - 2).is_irreducible():
print ("...reducible polynom mod %s :: X^4-2 = %s -> next prime..."
% (p, factor( X**4 - 2 )))
continue
print "%s is OK" % p
break
</code></pre>
<p>in order to get the first prime $p$ for which $X^4-2$ is irreducible in $\mathbb F_p[X]$. I could run the above code in my pycharm project.</p>
<p>Good luck!</p>
http://ask.sagemath.org/question/39742/make-pycharm-recognise-the-sage-python-interpreter/?comment=39822#post-id-39822A huge amount of good work, i highly appreciate this! The problem will have relevance, since the only way to be productive and to debug is by using an IDE. Triangles like (operating system) + (general purpose IDE) + (special program) always come with problems, mostly because the IDE was designed with a specific program (C, python, java, web devel, etc.) in mind, and sage uses python+batteries, so it is not exactly python.
Sorry, could not help more, the OS is needed to get into details.
Agreed, making sage available on all platforms (in a supported way, so that typing and executing code is comfortable) is a big important issue. For me, linux+eclipse+sage and/or linux+pycharm+sage do not work "as expected". Not only because of preparsing... So my solution is linux+emacs+sage.Mon, 27 Nov 2017 19:25:06 -0600http://ask.sagemath.org/question/39742/make-pycharm-recognise-the-sage-python-interpreter/?comment=39822#post-id-39822Comment by PHPirates for <p>This is a linux machine answering. The "answer" is possibly not the solution, but i need space to insert information, a comment is not enough. </p>
<p>In <a href="https://ask.sagemath.org/question/38750/how-i-use-sage-with-pycharm-in-ubuntu/">38750</a> the procedure was described for a linux machine. <code>sage -sh</code> sets all needed variables for the operating system. In my case:</p>
<pre><code>(sage-sh) dan@f... :~$ printenv | fgrep SAGE
</code></pre>
<p>gives the list of all more or less needed variables. Among them the most important one is</p>
<pre><code>SAGE_ROOT=/usr
</code></pre>
<p>The right corresponding value(s) should maybe be set for Windows.
Here is the list, well, i hesitated first to insert it, but soon we will see some of the variables again...</p>
<pre><code>$ printenv | fgrep SAGE
SAGE_DOC_SRC=/usr/share/doc/sage
SAGE_ETC=/usr/etc
SAGE_SHARE=/usr/share
SAGE_NUM_THREADS_PARALLEL=4
SAGE_STARTUP_FILE=/home/dan/.sage//init.sage
SAGE_SPKG_INST=/usr/var/lib/sage/installed
SAGE_ORIG_PATH_SET=True
SAGE_SRC=/usr/share/sage/source
SAGE_DOC=/usr/share/doc/sage
SAGE_LOCAL=/usr
SAGE_ENV_SOURCED=4
SAGE_REPO_ANONYMOUS=git://trac.sagemath.org/sage.git
SAGE_DOC_MATHJAX=True
SAGE_ORIG_PATH=/home/dan/bin:/usr/local/sbin:/usr/local/bin:/usr/bin:/usr/lib/jvm/default/bin:/usr/bin/site_perl:/usr/bin/vendor_perl:/usr/bin/core_perl
SAGE_LOGS=/usr/logs/pkgs
SAGE_EXTCODE=/usr/share/sage/ext
SAGE_ROOT=/usr
SAGE64=no
SAGE_DISTFILES=/usr/upstream
SAGE_NUM_THREADS=1
DOT_SAGE=/home/dan/.sage/
SAGE_REPO_AUTHENTICATED=ssh://git@trac.sagemath.org:2222/sage.git
</code></pre>
<p>A first try to set sage up and running in Windows is to insure that the Windows Python27 interpreter (that must be somewhere, possibly in <code>C:\Python27</code>) is found from the command line (running <code>cmd.exe</code>) and that inside of the python dialog box offered something like <code>from sage.all import *</code> is working...</p>
<p>Let me show the difference in Linux first. In a terminal...</p>
<pre><code>$ python2.7
Python 2.7.14 (default, Sep 20 2017, 02:02:23)
[GCC 7.2.0] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from sage.all import *
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python2.7/site-packages/sage/all.py", line 71, in <module>
from sage.env import SAGE_ROOT, SAGE_SRC, SAGE_DOC_SRC, SAGE_LOCAL, DOT_SAGE, SAGE_ENV
File "/usr/lib/python2.7/site-packages/sage/env.py", line 154, in <module>
SINGULAR_SO = SAGE_LOCAL+"/lib/libSingular."+extension
TypeError: unsupported operand type(s) for +: 'NoneType' and 'str'
>>>
</code></pre>
<p>Such information is hidden in the dark, when pycharm or an other IDE hits the issue.</p>
<p>The same after setting the right environment variables, using the simple <code>sage -sh</code> first:</p>
<pre><code>$ 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
(sage-sh) dan@f...:~$ python2.7
Python 2.7.14 (default, Sep 20 2017, 02:02:23)
[GCC 7.2.0] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from sage.all import *
>>> F = GF(2017)
>>> print F.multiplicative_generator()
5
</code></pre>
<p>My blind answer is to make the above first run from the command line in Windows. Then start pycharm against the right windows environment variables. In pycharm, or an other IDE, <strong>the python interpreter is still python27</strong>, not sage. To run sage inside, one has to do the above, possibly having to declare the libraries somewhere. In pycharm, this may be done using Settings > <strong>Project Structure</strong> . But my pycharm works without such a declaration.</p>
<p>Note that there is no pre-processing. So i have to type with contorsions something like...</p>
<pre><code>from sage.all import *
for p in primes( 10**20, 10**20 + 1000 ):
R = PolynomialRing( GF( p ), names='X' )
X = R.gens()[0]
if not (X**4 - 2).is_irreducible():
print ("...reducible polynom mod %s :: X^4-2 = %s -> next prime..."
% (p, factor( X**4 - 2 )))
continue
print "%s is OK" % p
break
</code></pre>
<p>in order to get the first prime $p$ for which $X^4-2$ is irreducible in $\mathbb F_p[X]$. I could run the above code in my pycharm project.</p>
<p>Good luck!</p>
http://ask.sagemath.org/question/39742/make-pycharm-recognise-the-sage-python-interpreter/?comment=39785#post-id-39785Found out that in my `C:/Program Files/SageMath 8.0/runtime/opt/sagemath-8.0/local/lib/python2.7/site-packages/sage/env.py` on line 88 it makes use of `os.uname`, only available on unix systems. There must be much more of these things, so I do not think this will ever work on Windows?
Thanks for all the help, and who knows maybe this question will become relevant in the future again :)Sat, 25 Nov 2017 04:32:20 -0600http://ask.sagemath.org/question/39742/make-pycharm-recognise-the-sage-python-interpreter/?comment=39785#post-id-39785Comment by PHPirates for <p>This is a linux machine answering. The "answer" is possibly not the solution, but i need space to insert information, a comment is not enough. </p>
<p>In <a href="https://ask.sagemath.org/question/38750/how-i-use-sage-with-pycharm-in-ubuntu/">38750</a> the procedure was described for a linux machine. <code>sage -sh</code> sets all needed variables for the operating system. In my case:</p>
<pre><code>(sage-sh) dan@f... :~$ printenv | fgrep SAGE
</code></pre>
<p>gives the list of all more or less needed variables. Among them the most important one is</p>
<pre><code>SAGE_ROOT=/usr
</code></pre>
<p>The right corresponding value(s) should maybe be set for Windows.
Here is the list, well, i hesitated first to insert it, but soon we will see some of the variables again...</p>
<pre><code>$ printenv | fgrep SAGE
SAGE_DOC_SRC=/usr/share/doc/sage
SAGE_ETC=/usr/etc
SAGE_SHARE=/usr/share
SAGE_NUM_THREADS_PARALLEL=4
SAGE_STARTUP_FILE=/home/dan/.sage//init.sage
SAGE_SPKG_INST=/usr/var/lib/sage/installed
SAGE_ORIG_PATH_SET=True
SAGE_SRC=/usr/share/sage/source
SAGE_DOC=/usr/share/doc/sage
SAGE_LOCAL=/usr
SAGE_ENV_SOURCED=4
SAGE_REPO_ANONYMOUS=git://trac.sagemath.org/sage.git
SAGE_DOC_MATHJAX=True
SAGE_ORIG_PATH=/home/dan/bin:/usr/local/sbin:/usr/local/bin:/usr/bin:/usr/lib/jvm/default/bin:/usr/bin/site_perl:/usr/bin/vendor_perl:/usr/bin/core_perl
SAGE_LOGS=/usr/logs/pkgs
SAGE_EXTCODE=/usr/share/sage/ext
SAGE_ROOT=/usr
SAGE64=no
SAGE_DISTFILES=/usr/upstream
SAGE_NUM_THREADS=1
DOT_SAGE=/home/dan/.sage/
SAGE_REPO_AUTHENTICATED=ssh://git@trac.sagemath.org:2222/sage.git
</code></pre>
<p>A first try to set sage up and running in Windows is to insure that the Windows Python27 interpreter (that must be somewhere, possibly in <code>C:\Python27</code>) is found from the command line (running <code>cmd.exe</code>) and that inside of the python dialog box offered something like <code>from sage.all import *</code> is working...</p>
<p>Let me show the difference in Linux first. In a terminal...</p>
<pre><code>$ python2.7
Python 2.7.14 (default, Sep 20 2017, 02:02:23)
[GCC 7.2.0] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from sage.all import *
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python2.7/site-packages/sage/all.py", line 71, in <module>
from sage.env import SAGE_ROOT, SAGE_SRC, SAGE_DOC_SRC, SAGE_LOCAL, DOT_SAGE, SAGE_ENV
File "/usr/lib/python2.7/site-packages/sage/env.py", line 154, in <module>
SINGULAR_SO = SAGE_LOCAL+"/lib/libSingular."+extension
TypeError: unsupported operand type(s) for +: 'NoneType' and 'str'
>>>
</code></pre>
<p>Such information is hidden in the dark, when pycharm or an other IDE hits the issue.</p>
<p>The same after setting the right environment variables, using the simple <code>sage -sh</code> first:</p>
<pre><code>$ 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
(sage-sh) dan@f...:~$ python2.7
Python 2.7.14 (default, Sep 20 2017, 02:02:23)
[GCC 7.2.0] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from sage.all import *
>>> F = GF(2017)
>>> print F.multiplicative_generator()
5
</code></pre>
<p>My blind answer is to make the above first run from the command line in Windows. Then start pycharm against the right windows environment variables. In pycharm, or an other IDE, <strong>the python interpreter is still python27</strong>, not sage. To run sage inside, one has to do the above, possibly having to declare the libraries somewhere. In pycharm, this may be done using Settings > <strong>Project Structure</strong> . But my pycharm works without such a declaration.</p>
<p>Note that there is no pre-processing. So i have to type with contorsions something like...</p>
<pre><code>from sage.all import *
for p in primes( 10**20, 10**20 + 1000 ):
R = PolynomialRing( GF( p ), names='X' )
X = R.gens()[0]
if not (X**4 - 2).is_irreducible():
print ("...reducible polynom mod %s :: X^4-2 = %s -> next prime..."
% (p, factor( X**4 - 2 )))
continue
print "%s is OK" % p
break
</code></pre>
<p>in order to get the first prime $p$ for which $X^4-2$ is irreducible in $\mathbb F_p[X]$. I could run the above code in my pycharm project.</p>
<p>Good luck!</p>
http://ask.sagemath.org/question/39742/make-pycharm-recognise-the-sage-python-interpreter/?comment=39784#post-id-39784I also tried `setx PYTHONPATH "C:/Program Files/SageMath 8.0/runtime/opt/sagemath-8.0/local/lib/python2.7/site-packages/sage" /M` (sets the system environment variable) in the hope that it would make python find the packages, but no luck.
A few years ago I managed to add a package (which included c libraries) to python and I think I did that by just pointing my PYTHONPATH to it, but can't remember exactly.
I know Sage is made for linux. But it's not for nothing that Sage was made available for Windows this summer. I think to make Sage more generally accepted it would help much if it would be available for Windows and it would have a proper IDE to work with. At least in my university it would, and I would very much like to spread the word of Sage, also to Windows!Sat, 25 Nov 2017 04:04:44 -0600http://ask.sagemath.org/question/39742/make-pycharm-recognise-the-sage-python-interpreter/?comment=39784#post-id-39784Comment by PHPirates for <p>This is a linux machine answering. The "answer" is possibly not the solution, but i need space to insert information, a comment is not enough. </p>
<p>In <a href="https://ask.sagemath.org/question/38750/how-i-use-sage-with-pycharm-in-ubuntu/">38750</a> the procedure was described for a linux machine. <code>sage -sh</code> sets all needed variables for the operating system. In my case:</p>
<pre><code>(sage-sh) dan@f... :~$ printenv | fgrep SAGE
</code></pre>
<p>gives the list of all more or less needed variables. Among them the most important one is</p>
<pre><code>SAGE_ROOT=/usr
</code></pre>
<p>The right corresponding value(s) should maybe be set for Windows.
Here is the list, well, i hesitated first to insert it, but soon we will see some of the variables again...</p>
<pre><code>$ printenv | fgrep SAGE
SAGE_DOC_SRC=/usr/share/doc/sage
SAGE_ETC=/usr/etc
SAGE_SHARE=/usr/share
SAGE_NUM_THREADS_PARALLEL=4
SAGE_STARTUP_FILE=/home/dan/.sage//init.sage
SAGE_SPKG_INST=/usr/var/lib/sage/installed
SAGE_ORIG_PATH_SET=True
SAGE_SRC=/usr/share/sage/source
SAGE_DOC=/usr/share/doc/sage
SAGE_LOCAL=/usr
SAGE_ENV_SOURCED=4
SAGE_REPO_ANONYMOUS=git://trac.sagemath.org/sage.git
SAGE_DOC_MATHJAX=True
SAGE_ORIG_PATH=/home/dan/bin:/usr/local/sbin:/usr/local/bin:/usr/bin:/usr/lib/jvm/default/bin:/usr/bin/site_perl:/usr/bin/vendor_perl:/usr/bin/core_perl
SAGE_LOGS=/usr/logs/pkgs
SAGE_EXTCODE=/usr/share/sage/ext
SAGE_ROOT=/usr
SAGE64=no
SAGE_DISTFILES=/usr/upstream
SAGE_NUM_THREADS=1
DOT_SAGE=/home/dan/.sage/
SAGE_REPO_AUTHENTICATED=ssh://git@trac.sagemath.org:2222/sage.git
</code></pre>
<p>A first try to set sage up and running in Windows is to insure that the Windows Python27 interpreter (that must be somewhere, possibly in <code>C:\Python27</code>) is found from the command line (running <code>cmd.exe</code>) and that inside of the python dialog box offered something like <code>from sage.all import *</code> is working...</p>
<p>Let me show the difference in Linux first. In a terminal...</p>
<pre><code>$ python2.7
Python 2.7.14 (default, Sep 20 2017, 02:02:23)
[GCC 7.2.0] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from sage.all import *
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python2.7/site-packages/sage/all.py", line 71, in <module>
from sage.env import SAGE_ROOT, SAGE_SRC, SAGE_DOC_SRC, SAGE_LOCAL, DOT_SAGE, SAGE_ENV
File "/usr/lib/python2.7/site-packages/sage/env.py", line 154, in <module>
SINGULAR_SO = SAGE_LOCAL+"/lib/libSingular."+extension
TypeError: unsupported operand type(s) for +: 'NoneType' and 'str'
>>>
</code></pre>
<p>Such information is hidden in the dark, when pycharm or an other IDE hits the issue.</p>
<p>The same after setting the right environment variables, using the simple <code>sage -sh</code> first:</p>
<pre><code>$ 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
(sage-sh) dan@f...:~$ python2.7
Python 2.7.14 (default, Sep 20 2017, 02:02:23)
[GCC 7.2.0] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from sage.all import *
>>> F = GF(2017)
>>> print F.multiplicative_generator()
5
</code></pre>
<p>My blind answer is to make the above first run from the command line in Windows. Then start pycharm against the right windows environment variables. In pycharm, or an other IDE, <strong>the python interpreter is still python27</strong>, not sage. To run sage inside, one has to do the above, possibly having to declare the libraries somewhere. In pycharm, this may be done using Settings > <strong>Project Structure</strong> . But my pycharm works without such a declaration.</p>
<p>Note that there is no pre-processing. So i have to type with contorsions something like...</p>
<pre><code>from sage.all import *
for p in primes( 10**20, 10**20 + 1000 ):
R = PolynomialRing( GF( p ), names='X' )
X = R.gens()[0]
if not (X**4 - 2).is_irreducible():
print ("...reducible polynom mod %s :: X^4-2 = %s -> next prime..."
% (p, factor( X**4 - 2 )))
continue
print "%s is OK" % p
break
</code></pre>
<p>in order to get the first prime $p$ for which $X^4-2$ is irreducible in $\mathbb F_p[X]$. I could run the above code in my pycharm project.</p>
<p>Good luck!</p>
http://ask.sagemath.org/question/39742/make-pycharm-recognise-the-sage-python-interpreter/?comment=39783#post-id-39783Oh thanks that is very interesting, because that means that you indeed managed to get the module installed in Python. The module is not in `C:\Python27\Lib\site-packages` for me (obviously) but only regular python packages. So I guess I need to figure out how to get the module there, and then PyCharm will be able to find it as a module. Any clue how you got it there?
Does, by any chance, your python2 `site-packages/sage` contain packages from algebras to typeset? I have those, and for every package an `all.pyc` as well, in the directory `C:\Program Files\SageMath 8.0\runtime\opt\sagemath-8.0\local\lib\python2.7\site-packages\sage`. I think this is the directory of Sage's python2?
After `sage -sh` then `printenv SAGE_ROOT` is correct, so that should be okay right?Sat, 25 Nov 2017 03:59:55 -0600http://ask.sagemath.org/question/39742/make-pycharm-recognise-the-sage-python-interpreter/?comment=39783#post-id-39783Comment by dan_fulea for <p>This is a linux machine answering. The "answer" is possibly not the solution, but i need space to insert information, a comment is not enough. </p>
<p>In <a href="https://ask.sagemath.org/question/38750/how-i-use-sage-with-pycharm-in-ubuntu/">38750</a> the procedure was described for a linux machine. <code>sage -sh</code> sets all needed variables for the operating system. In my case:</p>
<pre><code>(sage-sh) dan@f... :~$ printenv | fgrep SAGE
</code></pre>
<p>gives the list of all more or less needed variables. Among them the most important one is</p>
<pre><code>SAGE_ROOT=/usr
</code></pre>
<p>The right corresponding value(s) should maybe be set for Windows.
Here is the list, well, i hesitated first to insert it, but soon we will see some of the variables again...</p>
<pre><code>$ printenv | fgrep SAGE
SAGE_DOC_SRC=/usr/share/doc/sage
SAGE_ETC=/usr/etc
SAGE_SHARE=/usr/share
SAGE_NUM_THREADS_PARALLEL=4
SAGE_STARTUP_FILE=/home/dan/.sage//init.sage
SAGE_SPKG_INST=/usr/var/lib/sage/installed
SAGE_ORIG_PATH_SET=True
SAGE_SRC=/usr/share/sage/source
SAGE_DOC=/usr/share/doc/sage
SAGE_LOCAL=/usr
SAGE_ENV_SOURCED=4
SAGE_REPO_ANONYMOUS=git://trac.sagemath.org/sage.git
SAGE_DOC_MATHJAX=True
SAGE_ORIG_PATH=/home/dan/bin:/usr/local/sbin:/usr/local/bin:/usr/bin:/usr/lib/jvm/default/bin:/usr/bin/site_perl:/usr/bin/vendor_perl:/usr/bin/core_perl
SAGE_LOGS=/usr/logs/pkgs
SAGE_EXTCODE=/usr/share/sage/ext
SAGE_ROOT=/usr
SAGE64=no
SAGE_DISTFILES=/usr/upstream
SAGE_NUM_THREADS=1
DOT_SAGE=/home/dan/.sage/
SAGE_REPO_AUTHENTICATED=ssh://git@trac.sagemath.org:2222/sage.git
</code></pre>
<p>A first try to set sage up and running in Windows is to insure that the Windows Python27 interpreter (that must be somewhere, possibly in <code>C:\Python27</code>) is found from the command line (running <code>cmd.exe</code>) and that inside of the python dialog box offered something like <code>from sage.all import *</code> is working...</p>
<p>Let me show the difference in Linux first. In a terminal...</p>
<pre><code>$ python2.7
Python 2.7.14 (default, Sep 20 2017, 02:02:23)
[GCC 7.2.0] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from sage.all import *
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python2.7/site-packages/sage/all.py", line 71, in <module>
from sage.env import SAGE_ROOT, SAGE_SRC, SAGE_DOC_SRC, SAGE_LOCAL, DOT_SAGE, SAGE_ENV
File "/usr/lib/python2.7/site-packages/sage/env.py", line 154, in <module>
SINGULAR_SO = SAGE_LOCAL+"/lib/libSingular."+extension
TypeError: unsupported operand type(s) for +: 'NoneType' and 'str'
>>>
</code></pre>
<p>Such information is hidden in the dark, when pycharm or an other IDE hits the issue.</p>
<p>The same after setting the right environment variables, using the simple <code>sage -sh</code> first:</p>
<pre><code>$ 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
(sage-sh) dan@f...:~$ python2.7
Python 2.7.14 (default, Sep 20 2017, 02:02:23)
[GCC 7.2.0] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from sage.all import *
>>> F = GF(2017)
>>> print F.multiplicative_generator()
5
</code></pre>
<p>My blind answer is to make the above first run from the command line in Windows. Then start pycharm against the right windows environment variables. In pycharm, or an other IDE, <strong>the python interpreter is still python27</strong>, not sage. To run sage inside, one has to do the above, possibly having to declare the libraries somewhere. In pycharm, this may be done using Settings > <strong>Project Structure</strong> . But my pycharm works without such a declaration.</p>
<p>Note that there is no pre-processing. So i have to type with contorsions something like...</p>
<pre><code>from sage.all import *
for p in primes( 10**20, 10**20 + 1000 ):
R = PolynomialRing( GF( p ), names='X' )
X = R.gens()[0]
if not (X**4 - 2).is_irreducible():
print ("...reducible polynom mod %s :: X^4-2 = %s -> next prime..."
% (p, factor( X**4 - 2 )))
continue
print "%s is OK" % p
break
</code></pre>
<p>in order to get the first prime $p$ for which $X^4-2$ is irreducible in $\mathbb F_p[X]$. I could run the above code in my pycharm project.</p>
<p>Good luck!</p>
http://ask.sagemath.org/question/39742/make-pycharm-recognise-the-sage-python-interpreter/?comment=39774#post-id-39774On this linux machine, `sage-all` is found here:
sage: print sage.all
<module 'sage.all' from '/usr/lib/python2.7/site-packages/sage/all.pyc'>
Is there any corresponding entry in the Windows `site-packages` installation?
Also, does `sage -sh` really set the `SAGE*` environment variables?! Please try
sage -sh
set SAGE
in the windows command line window ( alias `cmd` ) .
(I'm just trying to get closer to the source of the problem, which is still far away - i think.)
(A way to avoid all such problems is to install sage on linux and use it for mathematical / scientific production. This comment should please not be understood as an operating system discussion, it is only a comment about the way in which a system, a program **supports** a task, or only makes it possible.)Fri, 24 Nov 2017 15:41:27 -0600http://ask.sagemath.org/question/39742/make-pycharm-recognise-the-sage-python-interpreter/?comment=39774#post-id-39774Comment by PHPirates for <p>This is a linux machine answering. The "answer" is possibly not the solution, but i need space to insert information, a comment is not enough. </p>
<p>In <a href="https://ask.sagemath.org/question/38750/how-i-use-sage-with-pycharm-in-ubuntu/">38750</a> the procedure was described for a linux machine. <code>sage -sh</code> sets all needed variables for the operating system. In my case:</p>
<pre><code>(sage-sh) dan@f... :~$ printenv | fgrep SAGE
</code></pre>
<p>gives the list of all more or less needed variables. Among them the most important one is</p>
<pre><code>SAGE_ROOT=/usr
</code></pre>
<p>The right corresponding value(s) should maybe be set for Windows.
Here is the list, well, i hesitated first to insert it, but soon we will see some of the variables again...</p>
<pre><code>$ printenv | fgrep SAGE
SAGE_DOC_SRC=/usr/share/doc/sage
SAGE_ETC=/usr/etc
SAGE_SHARE=/usr/share
SAGE_NUM_THREADS_PARALLEL=4
SAGE_STARTUP_FILE=/home/dan/.sage//init.sage
SAGE_SPKG_INST=/usr/var/lib/sage/installed
SAGE_ORIG_PATH_SET=True
SAGE_SRC=/usr/share/sage/source
SAGE_DOC=/usr/share/doc/sage
SAGE_LOCAL=/usr
SAGE_ENV_SOURCED=4
SAGE_REPO_ANONYMOUS=git://trac.sagemath.org/sage.git
SAGE_DOC_MATHJAX=True
SAGE_ORIG_PATH=/home/dan/bin:/usr/local/sbin:/usr/local/bin:/usr/bin:/usr/lib/jvm/default/bin:/usr/bin/site_perl:/usr/bin/vendor_perl:/usr/bin/core_perl
SAGE_LOGS=/usr/logs/pkgs
SAGE_EXTCODE=/usr/share/sage/ext
SAGE_ROOT=/usr
SAGE64=no
SAGE_DISTFILES=/usr/upstream
SAGE_NUM_THREADS=1
DOT_SAGE=/home/dan/.sage/
SAGE_REPO_AUTHENTICATED=ssh://git@trac.sagemath.org:2222/sage.git
</code></pre>
<p>A first try to set sage up and running in Windows is to insure that the Windows Python27 interpreter (that must be somewhere, possibly in <code>C:\Python27</code>) is found from the command line (running <code>cmd.exe</code>) and that inside of the python dialog box offered something like <code>from sage.all import *</code> is working...</p>
<p>Let me show the difference in Linux first. In a terminal...</p>
<pre><code>$ python2.7
Python 2.7.14 (default, Sep 20 2017, 02:02:23)
[GCC 7.2.0] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from sage.all import *
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python2.7/site-packages/sage/all.py", line 71, in <module>
from sage.env import SAGE_ROOT, SAGE_SRC, SAGE_DOC_SRC, SAGE_LOCAL, DOT_SAGE, SAGE_ENV
File "/usr/lib/python2.7/site-packages/sage/env.py", line 154, in <module>
SINGULAR_SO = SAGE_LOCAL+"/lib/libSingular."+extension
TypeError: unsupported operand type(s) for +: 'NoneType' and 'str'
>>>
</code></pre>
<p>Such information is hidden in the dark, when pycharm or an other IDE hits the issue.</p>
<p>The same after setting the right environment variables, using the simple <code>sage -sh</code> first:</p>
<pre><code>$ 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
(sage-sh) dan@f...:~$ python2.7
Python 2.7.14 (default, Sep 20 2017, 02:02:23)
[GCC 7.2.0] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from sage.all import *
>>> F = GF(2017)
>>> print F.multiplicative_generator()
5
</code></pre>
<p>My blind answer is to make the above first run from the command line in Windows. Then start pycharm against the right windows environment variables. In pycharm, or an other IDE, <strong>the python interpreter is still python27</strong>, not sage. To run sage inside, one has to do the above, possibly having to declare the libraries somewhere. In pycharm, this may be done using Settings > <strong>Project Structure</strong> . But my pycharm works without such a declaration.</p>
<p>Note that there is no pre-processing. So i have to type with contorsions something like...</p>
<pre><code>from sage.all import *
for p in primes( 10**20, 10**20 + 1000 ):
R = PolynomialRing( GF( p ), names='X' )
X = R.gens()[0]
if not (X**4 - 2).is_irreducible():
print ("...reducible polynom mod %s :: X^4-2 = %s -> next prime..."
% (p, factor( X**4 - 2 )))
continue
print "%s is OK" % p
break
</code></pre>
<p>in order to get the first prime $p$ for which $X^4-2$ is irreducible in $\mathbb F_p[X]$. I could run the above code in my pycharm project.</p>
<p>Good luck!</p>
http://ask.sagemath.org/question/39742/make-pycharm-recognise-the-sage-python-interpreter/?comment=39770#post-id-39770(edited comment)
Okay so I'm running now inside sage shell
`SAGE_ROOT="C:/Program Files/SageMath 8.0/runtime/opt/sagemath-8.0"`
`sage -sh`
`cd "C:/Program Files/JetBrains/PyCharm 2017.2.3/bin"`
`./pycharm.exe`
but in pycharm I get `no module named sage.all`. (I selected my system wide python2.7 as interpreter). That also happens when trying to import sage from python2 in the normal command prompt.Fri, 24 Nov 2017 04:40:16 -0600http://ask.sagemath.org/question/39742/make-pycharm-recognise-the-sage-python-interpreter/?comment=39770#post-id-39770