Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
816 views
in Technique[技术] by (71.8m points)

windows - Permanently set Python path for Anaconda within Cygwin

I'm trying to install Anaconda on my Windows 7 machine. I often use cygwin to for my command-line work, and I would like to manage Anaconda from there. I've worked through the graphic installer without any issues, and checked necessary boxes to reset my default path to this install of python. I go ahead to check where python is and initially I get this...

$ which python
/usr/bin/python

From here python works fine...

$ python
Python 2.7.5 (default, Oct  2 2013, 22:34:09)
[GCC 4.8.1] on cygwin
Type "help", "copyright", "credits" or "license" for more information.

But I'm trying to work from anaconda, so I should just need to redefine my path...

$ export PATH=/cygdrive/c/anaconda:$PATH
$ which python
/cygdrive/c/anaconda/python

And now I should be good to go, but when I try and step into python, it just hangs

$ python

Any idea why this might be happening? verbose return, below...

$ python -v
# installing zipimport hook
import zipimport # builtin
# installed zipimport hook
# C:anacondalibsite.pyc matches C:anacondalibsite.py
import site # precompiled from C:anacondalibsite.pyc
# C:anacondalibos.pyc matches C:anacondalibos.py
import os # precompiled from C:anacondalibos.pyc
import errno # builtin
import nt # builtin
# C:anacondalib
tpath.pyc matches C:anacondalib
tpath.py
import ntpath # precompiled from C:anacondalib
tpath.pyc
# C:anacondalibstat.pyc matches C:anacondalibstat.py
import stat # precompiled from C:anacondalibstat.pyc
# C:anacondalibgenericpath.pyc matches C:anacondalibgenericpath.py
import genericpath # precompiled from C:anacondalibgenericpath.pyc
# C:anacondalibwarnings.pyc matches C:anacondalibwarnings.py
import warnings # precompiled from C:anacondalibwarnings.pyc
# C:anacondaliblinecache.pyc matches C:anacondaliblinecache.py
import linecache # precompiled from C:anacondaliblinecache.pyc
# C:anacondalibypes.pyc matches C:anacondalibypes.py
import types # precompiled from C:anacondalibypes.pyc
# C:anacondalibUserDict.pyc matches C:anacondalibUserDict.py
import UserDict # precompiled from C:anacondalibUserDict.pyc
# C:anacondalib\_abcoll.pyc matches C:anacondalib\_abcoll.py
import _abcoll # precompiled from C:anacondalib\_abcoll.pyc
# C:anacondalibabc.pyc matches C:anacondalibabc.py
import abc # precompiled from C:anacondalibabc.pyc
# C:anacondalib\_weakrefset.pyc matches C:anacondalib\_weakrefset.py
import _weakrefset # precompiled from C:anacondalib\_weakrefset.pyc
import _weakref # builtin
# C:anacondalibcopy_reg.pyc matches C:anacondalibcopy_reg.py
import copy_reg # precompiled from C:anacondalibcopy_reg.pyc
# C:anacondalibraceback.pyc matches C:anacondalibraceback.py
import traceback # precompiled from C:anacondalibraceback.pyc
# C:anacondalibsysconfig.pyc matches C:anacondalibsysconfig.py
import sysconfig # precompiled from C:anacondalibsysconfig.pyc
# C:anacondalib
e.pyc matches C:anacondalib
e.py
import re # precompiled from C:anacondalib
e.pyc
# C:anacondalibsre_compile.pyc matches C:anacondalibsre_compile.py
import sre_compile # precompiled from C:anacondalibsre_compile.pyc
import _sre # builtin
# C:anacondalibsre_parse.pyc matches C:anacondalibsre_parse.py
import sre_parse # precompiled from C:anacondalibsre_parse.pyc
# C:anacondalibsre_constants.pyc matches C:anacondalibsre_constants.py
import sre_constants # precompiled from C:anacondalibsre_constants.pyc
# C:anacondaliblocale.pyc matches C:anacondaliblocale.py
import locale # precompiled from C:anacondaliblocale.pyc
import encodings # directory C:anacondalibencodings
# C:anacondalibencodings\__init__.pyc matches C:anacondalibencodings\__init__.py
import encodings # precompiled from C:anacondalibencodings\__init__.pyc
# C:anacondalibcodecs.pyc matches C:anacondalibcodecs.py
import codecs # precompiled from C:anacondalibcodecs.pyc
import _codecs # builtin
# C:anacondalibencodingsaliases.pyc matches C:anacondalibencodingsaliases.py
import encodings.aliases # precompiled from C:anacondalibencodingsaliases.pyc
import operator # builtin
# C:anacondalibfunctools.pyc matches C:anacondalibfunctools.py
import functools # precompiled from C:anacondalibfunctools.pyc
import _functools # builtin
import _locale # builtin
# C:anacondalibencodingscp1252.pyc matches C:anacondalibencodingscp1252.py
import encodings.cp1252 # precompiled from C:anacondalibencodingscp1252.pyc
# zipimport: found 13 names in C:anacondalibsite-packages
unipy-0.1.0-py2.7.egg
# zipimport: found 144 names in C:anacondalibsite-packagessetuptools-3.6-py2.7.egg
Python 2.7.7 |Anaconda 2.0.1 (64-bit)| (default, Jun 11 2014, 10:40:02) [MSC v.1500 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
Anaconda is brought to you by Continuum Analytics.
Please check out: http://continuum.io/thanks and htt

Another (possibly related) issue I'm having is needing to reset the path every time I close/open cygwin. I've entered the following text into .bashrc and .profile to try and set the path permanently:

# Set path to python from anaconda install
export PATH=/cygdrive/c/anaconda:$PATH

After opening and closing cygwin, I return to:

$ which python
/usr/bin/python

Could this be related to setting certain system environment variables?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

To work with the interactive Python shell in Cygwin I use the -i option.

To get it from the Anaconda install, I used the steps suggested above:

$ export PATH=/cygdrive/c/anaconda:$PATH
$ which python
/cygdrive/c/anaconda/python

Then I launch python within Cygwin with the -i option:

$ python -i
Python 2.7.8 |Anaconda 2.1.0 (64-bit)| (default, Jul  2 2014, 15:12:11) [MSC v.1500 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
Anaconda is brought to you by Continuum Analytics.
Please check out: http://continuum.io/thanks and https://binstar.org
>>>>

The libraries are also working fine. For instance the pandas library (which has been installed through Anaconda) can be imported now.

>>>> import pandas
>>>> pandas.DataFrame
<class 'pandas.core.frame.DataFrame'>

Now to make this permanent I added the path in my bashrc file:

$ echo 'export PATH=/cygdrive/c/anaconda:$PATH' >> .bashrc
$ source .bashrc
$ which python
/cygdrive/c/anaconda/python

I hope this helps.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...