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.

In 38750 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!