How can I make cygwin aware of enthought python? - python

I need scipy on cygwin, so I figured the quickest way to make it work would have been installing enthought python. However, I then realized I have to make cygwin aware of enthought before I can use it, e.g. so that calling Python from the cygwin shell I get the enthought python (with scipy) rather than the cygwin one.
How do I do that?
I can guess my question is easy, but I'm just learning about all of this and so please be patient :-)

Think about uninstalling the cygwin version of Python, at least to start with. It's easy enough to reinstall later.
Copy your Windows path.
Install the Windows version of Enthought Python.
Examine the new Windows path. The new entries probably have to be transferred to your bash shell in cygwin. (I haven't seen Enthought. There might be more than one new path entry.) But test without changing the bash path, just to be sure.
Add the new path entries to, umm, .bashrc, I think. The path under cygwin will be a colon delimited string. You'll need to use the /cygdrive path; expect to use an entry like this to put Entought in the path.
/cygdrive/c/Program Files/Enthought
To actually do that, edit .bashrc, and put these two lines (or something like them) at the end.
PATH=$PATH:/cygdrive/c/Program\ Files/Enthought
export PATH
Note that the backslash allows proper interpretation of spaces in file paths. The export statement guarantees that programs called by bash will also include that path.

Just put the directory with enthought python before the directory with Cygwin's python in your path. If both are in the same directory, use ln to create a symbolic link, store it in another directory, and place it higher in your path. The previous answer has instructions to add it to your path.

Related

How to use Windows Python install in MSYS2

I am using MSYS2 as my terminal in Visual Studio Code for GCC support and to use a few tools that are easier to build often in a Linux environment. However, I would like to install Python on Windows and use that instead of Python packaged with MSYS2. My current workaround is to define the following alias in my .bashrc:
alias python='$PYTHONPATH/../../python.exe'
alias pip='$PYTHONPATH/../../pip.exe'
I recently tried using venv and that is causing problems as when I type python from the MINGW terminal, it points to my Windows python instead of the venv python. This is not a bug obviously, but I need a way to use Windows python instead of MSYS2 python for packages like numpy, tox, matplotlib, etc. because the MSYS2 packages for those are a headache and currently, tox+pytest in MSYS2 does not work. At this time, my solution above works for everything I've thrown at it in Python.
So, my question is how do I use my Windows Python install instead of the POSIX/Windows MSYS2 Python without the above hack? Is there a way I can define the PATH to include my Windows Python as the first entries in MSYS2 PATH?
Here is what it looks like right now:
$echo $PATH
/mingw64/bin:/usr/local/bin:/usr/bin:/bin:/c/Users/Glen.Nicholls/AppData/Local/Programs/Python/Python37/Scripts:/c/Users/Glen.Nicholls/AppData/Local/Programs/Python/Python37
I would like to know how to make it the following instead, delete python from MSYS2, or find another way to accomplish this.
/c/Users/Glen.Nicholls/AppData/Local/Programs/Python/Python37/Scripts:/c/Users/Glen.Nicholls/AppData/Local/Programs/Python/Python37:/mingw64/bin:/usr/local/bin:/usr/bin:/bin:...
You have to put the path for /c/Users/Glen.Nicholls/AppData/Local/Programs/Python/Python37 and /c/Users/Glen.Nicholls/AppData/Local/Programs/Python/Python37/Scripts before those on the msys2, right? Then I wouldn't try to use the terminal as it's too tricky, so, I will use the control panel to do it more easily. Here are some screenshots how I will do that for you.
(Sorry that I couldn't put the pictures, but the links for them instead, I couldn't put any pictures as I am a new member. Also, sorry I made the instructions too detailed.)
First, open search box with Windows+S key.
Then, choose the environment variables options from the window.
Then, choose the PATH system variable at the bottom section, and choose edit (the upper is the user PATH, and the bottom is the system PATH)
This is how it looked before:--
Then, choose C:/Users/Glen.Nicholls/AppData/Local/Programs/Python/Python37 and click “Move Up” until done. Likewise, do it same with “C:/Users/Glen.Nicholls/AppData/Local/Programs/Python/Python37/Scripts” until it's on the top.
This is how it looks now:--
After you are done, restart your terminal and hopefully, it will work. :D

Why (or why not) Add Anaconda to path?

I have found a partial answer in this question:
Adding Anaconda to Path or not
But I still don't fully understand. I have had a lot of installation issues when switching from a normal installation Python to Anaconda, requiring me to completely re-install Windows... So i want to get this right now.
What happens internally when I Add Anaconda (or python for that matter) to the PATH? I plan on working with seperate conda environments for different python versions, what could go wrong if I add Anaconda to path in the installation? And what is the difference between doing it in the installation or doing it later through the command prompt? Will it affect my ability to integrate anaconda with PyCharm?
PATH is an environment variable that is a list of locations where executable programs lie (see also the wikipedia page.
Whenever you are in your command line and try to execute some program, for example regedit, then the cmd does not magically know that you mean C:\Windows\regedit.exe. Instead, it searches all locations in your PATH for an executable named regedit and finds it in C:\Windows which is one of the standard parts of PATH in Windows.
That is also, why messing with the PATH can be dangerous if you don't know what you are doing, because it might lead to things not working anymore if, for example you delete parts of the path or add custom directories to it.
That being said, you should now have an idea what happens when you "Add anaconda to path". It simply means, that Anaconda adds the directory where its executables lie to the PATH, hence making it findable when, for example you type conda in your cmd.
That being said, adding Anaconda to PATH is something that is convenient, because the commands can always be found automatically and they will also be found by other programs scanning your PATH for a python executable.
At the same time it is not necessary. When you use e.g. pycharm, then you can specify the path to the interpreter inside of pycharm. it does not necessarily need to be present in your PATH.
Note:
I personally have it on my PATH because I am too lazy to open an Anaconda prompt each time I need it in a cmd and I do not see the harm in it if you understand the consequences and its my only python installation anyway.
Also Helpful:
On windows, you can use the where command to find out from where commands are loaded. For example:
where regedit
gives
C:\Windows\regedit.exe
This can be especially helpful when trying to debug PATH issues
The python.exe of the base environment resides in the
C:\Users\USERNAME\AppData\Local\Anaconda3 folder
If you add this folder to the PATH, you can call that version directly from the prompt and Python will also find many of the installed packages via that anchor folder. However, this is not true for e.g. the Numpy package which heavily depends on compiled C libraries. So you would also need to add the following folders to the PATH:
C:\Users\USERNAME\AppData\Local\Anaconda3\Library\mingw-w64\bin;
C:\Users\USERNAME\AppData\Local\Anaconda3\Library\usr\bin;
C:\Users\USERNAME\AppData\Local\Anaconda3\Library\bin;
C:\Users\USERNAME\AppData\Local\Anaconda3\Scripts;
C:\Users\USERNAME\AppData\Local\Anaconda3\bin;
This is exctly what the activation is for, plus it also gives you the option to easily switch between environments.
Bottom line: Adding Anaconda to the PATH might help in simple cases, but the whole concept of Anaconda's dependency management depends on environments and their activation. It's better to use Anacona the proper way right from the beginning and NOT to add Anaconda to the PATH.

How can I make my PATH more succinct in ZSH?

I am using ZSH. I was having trouble running the Anaconda package manager commands in my terminal. I found that I could add the bin to my PATH using this code:
export PATH="$HOME/anaconda3/bin:$PATH"
That worked. All of the Anaconda and associated commands work and it left me with this PATH:
/Users/USER/anaconda3/bin:/Library/Frameworks/Python.framework/Versions/3.6/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/opt/X11/bin
But the PATH variable would reset each time I closed the terminal window. After some research, I figured out how modify my .zshrc to make it permanent. I simply pasted this into my .zshrc:
export PATH=/Users/USER/anaconda3/bin:/Library/Frameworks/Python.framework/Versions/3.6/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/opt/X11/bin
All the commands work and are permanent, but aren't I setting myself up for failure down the road? Everything in the PATH, minus the "/Users/USER/anaconda3/bin" were set automatically. What happens when I update Python, for example? How can I include the "USER/anaconda3/bin" portion of my PATH in my .zshrc without being so explicit?
Your PATH concern is not zsh specific. You could organize things differently.
For example, you could decide to add a directory $HOME/bin/ early in your PATH and put inside that $HOME/bin/ symbolic links to the executables (or scripts) that you want to use. BTW, I recommend to have a short PATH (containing some $HOME/bin/ etc...) since it is more efficient and less messy to understand.
What happens when I update Python, for example?
Let's suppose that Python is installed in your system in /usr/bin/python (and that you use some Linux distribution -or some other Unix- with a good package manager dealing with that;on MacOSX consider homebrew). When that file /usr/bin/python is updated, any future exec of it (e.g. by some shell) will use the new version. Read carefully execve(2).
If ou have several Python-s and the one you want to use is under /Library/Frameworks/Python.framework/Versions/3.6/bin and you upgraded it to some Python 3.7 installed under /Library/Frameworks/Python.framework/Versions/3.7/bin you would need to change your PATH.
If you followed my suggestion, you would (for example) just have a symlink from $HOME/bin/python to /Library/Frameworks/Python.framework/Versions/3.6/bin/python and you would upgrade that symlink when installing Python3.7 using for example:
# remove the old symlink
rm -v $HOME/bin/python
# add the new one
ln -sv /Library/Frameworks/Python.framework/Versions/3.7/bin/python \
$HOME/bin/python
In all cases, you are responsible of having a good enough PATH (and preferably a short one).

Remove old Python Installation in MAC OS

I installed python using MacPort and I am satisfied with the result, but found that there are other versions of Python installed in other directories, and can not remember how they were instaldas, it's been five years that use this notebook and perhaps installed by other means a few years.
I tried to remove all references to extra Python, beyond that were installed with MacPorts, but do not think like, I tried to remove the directories with the command rm -rfmas even using sudo rm -rf have success.
The old instalation are in directories:
/System/Library/Frameworks/Python.framework/Versions/
/Library/Python/
How to discover the origin of such facilities and remove permanently?
Don't remove the system Pythons. They may be used by other programs. (I don't know if anything on OS X actually uses them, but it's best to keep them.)
Instead, just make sure that your MacPorts bin directory (at /opt/local/bin) is first on your $PATH.
Don't! The name /Library and /System suggest that they are OS-level directories. Nobody installed them. Instead, Mac and other linux-based systems use them by default for system-level services (and they should not be even manually upgraded or system stability may suffer).
For all what matters, you should just prepend your installation directory to a system variable called PATH in your $HOME/.bashrc file. Then, whenever YOU use python, the system will always search for the first occurrence of python on PATH, which is your python. Open terminal, enter the following command (once in a life time):
echo "PATH={a-path-to-the-folder-containing-your-executable-python}:\$PATH" >> $HOME/.bashrc
To explain it, the quoted command prepends your installation directory as the first place to search for executable files. The >> $HOME/.bashrc write this command to the last line of .bashrc, which is a file that setup your terminal environment automatically upon login.

Clean up the Python installation

It seems that python can be found in three different places in my Mac OS. See below. Is there anything wrong? Should I and how can I clean up my python installation without reinstalling the OS? In fact, I recently experience some strange behavior when using Python.
'/usr/local/Cellar/python/2.7.9/Frameworks/Python.framework/Versions/2.7/lib/python2.7/,
'/usr/local/lib/python2.7/site-packages',
'/Library/Python/2.7/site-packages',
What you need to do is update the paths in your .bashrc (or more likely .profile as you are on mac). This should be accessible from your home directory. ~/.profile and can be edited using nano.
You can then tell your terminal which set of libraries and version of python to use by adding the following. Note more than one may be added this way, so only have one bin directory with an executable python program!
export PATH=$PATH:/usr/local/lib/python2.7/site-packages
If you want to add other libraries / execute your own programs as if they were in the library or save yourself reinstalling everything, you can use the following:
export PYTHONPATH=/Library/Python/2.7/site-packages'
Finally if you wanted to run a script/preload libraries every time you open python, you can make a .pythonstartup file in your home directory as well.
export PYTHONSTARTUP=$HOME/.pythonstartup
As for cleaning up, most distributions tend to update you paths when they are installed, which is most likely what is causing your problems. So all you probably have to do is look at your .profile file and remove two of the three paths above.
Hope that helps!

Categories

Resources