Uninstalling Canopy Enthought leaves strange bash warning? - python

So I uninstalled Enthought Canopy (I think completely, but I'm unsure if there's residual information hanging around that I neglected to modify).
After uninstalling, following the directions here: https://support.enthought.com/entries/23580651-Uninstalling-and-resetting-Canopy
I was slightly unsettled by the fact that I couldn't find anything to delete for step 5, and since Canopy was never my default Python environment, I didn't think too much of it.
But now, every time I open terminal, I get this warning:
"-bash: /Users/MyName/Library/Enthought/Canopy_64bit/User/bin/activate: No such file or directory"
What do I need to do to fix this? I'm running Mac OSX, 10.8.5 (Mountain Lion). Any help would be much appreciated.

Until today I had this exact same problem, and it really bothered me. I solved it this way:
First, I entered following command in the terminal: open -a TextEdit .bash_profile
This opens your .bash_profile in TextEdit, which for a terminal novice like me at least, is easier than editing it in the terminal with vi or something like that. In that file, you should see a few lines related to "Canopy" and "Enthought". In my case, this is what showed up:
# Added by Canopy installer on 2014-02-11
# VIRTUAL_ENV_DISABLE_PROMPT can be set to '' to make bashprompt show that Canopy is active, otherwise 1
VIRTUAL_ENV_DISABLE_PROMPT=1 source /Users/MyUserame/Library/Enthought/Canopy_64bit/User/bin/activate
I think it is that last line that is causing all the trouble. Simply delete these few lines (don't delete anything else). In my case, these lines were in a separate block from others in my .bash_profile so it was easy to pick them out. After this, just close the text file, restart your computer, and the annoying stuff about Enthought not being found should be gone. For me this worked, hope it does for you too!

To find out where this is, run an interactive shell with the xtracefd flag set and a PS4 that includes $BASH_SOURCE. For instance:
PS4='+$BASH_SOURCE:$LINENO:' bash -i -x
Then, look through the output for the first reference to the activate script given; it will include the source file and line number.
Most likely, this will be .bashrc.

For anyone who is having this problem as I did, I found the source in my .profile file. You will see a command at the top of your .bash_profile or .bashrc that reads: [[ -s "$HOME/.profile" ]] && source "$HOME/.profile" # Load the default .profile. This is calling yet another script called .profile that you need to clean up. To edit .profile use the command:
open -a TextEdit .profile
Then you'll find a line in there that says something like:
# Added by Canopy installer on 2013-04-10
source /Users/username/Library/Enthought/Canopy_64bit/User/bin/activate
Delete those lines and save, et voila!

I had a similar error message. You need to comment out (#) or delete the last line thats under the #Canopy settings in your bash profile. follow below steps in terminal to get rid of the error message:
vim .profile
You should see the following info regarding your Canopy set up:
# Added by Canopy installer on 2016-01-12
# VIRTUAL_ENV_DISABLE_PROMPT can be set to '' to make bashprompt show that Canopy is active, otherwise 1
VIRTUAL_ENV_DISABLE_PROMPT=1 source '/Users/waismoradi/Documents/CanopyEnthought/User/bin/activate'
Just delete or comment out with -> # the last line and you are all set! This will disable the env prompt to show up when you launch terminal.

Related

How to SIMPLY configure VIM for Python?

Note: A previous question was closed because it needed to be more "focused", so I deleted the old one and modified the question so it only focus on VIM for Python.
I want to start using VIM but I´m having a hard time configuring it.
First, I did :syntax on to add some color to the syntax. Then, I wanted to change the version of Python that VIM is "verifying" as default (version 2+) to the recent version (3+) and did (something I found online) :let g:syntastic_python_python_exec = 'python3'. After I did this, the :syntax on stopped working (no more syntax highlighting) and VIM still didn´t support python3. What I mean is that if I write in Python3 I get error because it doesn't recognize version 3+
I´m using VIM (version 8+) from Terminal on Mac High Sierra.
Question:
How can I configure VIM to work with Python ? - to work with recent version of Python(3+), have syntax highlight ON and have a "file tree".
Please, answer as simply as possible so anyone who is new to VIM can understand. I searched a lot and the answers I found were old and confusing to understand for someone who is new to VIM and wants to start with it.
For the file tree, I would suggest the NerdTree plugin.
As for your syntax checker not working, I suggest you first create a Python 3 virtual environment via Pipenv, then open your vim within that virtual environment. That might solve your problem. You should always be using a virtual environment in any case if you are writing Python code.
I would suggest using coc.nvim. It is not entirely simple, but it is the simplest I know after trying a few alternatives.
Here is a relatively simple guide:
First install vim-plug: In your terminal, enter
curl -fLo ~/.vim/autoload/plug.vim --create-dirs \
https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim
Then install coc.nvim:
This plugin requires nodejs,
curl -sL install-node.now.sh/lts | bash
Now put this code in your ~/.vimrc
call plug#begin('~/.vim/plugged')
Plug 'neoclide/coc.nvim', {'branch': 'release'}
call plug#end()
Restart Vim, and type :PlugInstall and press enter. This will install the plugin for you.
Copy the default example vim configuration to the end of your ~/.vimrc (or anywhere after the plug#end()).
Inside vim, issue the command :CocInstall coc-python. This will install coc-python, which is their python support.
Inside vim, issue the command :CocConfig. This will open up a file coc-settings.json. Put in the following code in the file to use MS's Python language server.
{
"python.jediEnabled": false
}
Note that you can use jedi as well. I'm opting for MS because it's simpler to setup.
Restart vim and open a .py file. It will take a moment to install MS Python language server. After that, you should get syntax analysis and code completion.
To select an interpreter (python3), do :CocCommand, and you should see an option to set the interpreter. For virtual environments to show up, you can activate the virtual env in the command line before starting vim.

most of terminal commands do not work

I am new to python and OSX terminal commands. I wanted to permanently add a directory to PYTHONPATH, thus I looked here and used these instructions:
1-Open up Terminal
2-Type open .bash_profile
3-In the text file that pops up, add this line at the end: export PYTHONPATH=$PYTHONPATH:foo/bar
4-Save the file, restart the Terminal, and you're done
I also followed this instruction:
export PYTHONPATH="${PYTHONPATH}:/my/other/path"
After these changes I cannot use any command like python, which, whereis, pip, etc. in Terminal :(
The response is something like below:
-bash: which: command not found
I do not know what I have done.
are you sure you have appended the path because what i can see is you have replaced old path definition and assigned a new one
remove bash profile use one of these commands /bin/rm ~/.bash_profile Or if you want to save your current bash configs then use a mv instead /bin/mv ~/.bash_profile ~/bash_profile Then close your terminal and start again you will be able to use all commands and apps

Trying to directly run .py file using Enthought Canopy Python on Windows 7

I am trying to set up Canopy with Windows so that it will not, by default, try to open as a GUI. Essentially I want to do exactly this:
http://docs.enthought.com/canopy/configure/canopy-cli.html#create-epd-dist
The only problem is that the instructions listed here do not seem to work as expected.
Here's what I want to happen. I have a folder full of scripts. The folder (my_program/) is in my path. I want to call script_1.py on the command line from any directory and have it execute. With the old Enthought distribution this is what happens. It is also what happens with Canopy on Mac. However, running Canopy on Windows, instead the Canopy GUI pops up with script_1.py open for editing.
I ran this command as in the docs:
Canopy\App\Canopy_cli.exe setup C:\Python27 --set-default
It created a "Canopy 64 bit (standalone) Command Prompt" in addition to the regular Command Prompt. However, the behavior in both this new Command Prompt and the regular Command Prompt remains the same -- script_1.py simply opens the Canopy GUI.
Here is my PATH variable:
c:\python27\scripts;
c:\users\****\appdata\local\enthought\canopy\user\scripts;
C:\Users\****\AppData\Local\Enthought\Canopy\User;
C:\Users\****\AppData\Local\Enthought\Canopy\User\Scripts;
C:\Python27;
C:\Python27\Scripts;
C:\Users\****\Documents\my_program;
Any ideas why I'm not able to set up Canopy as an EPD-like environment, or how to do so? Thanks!
Update:
First, I ran this command as Jonathan March outlined in his answer:
ftype Python.File=c:\Users\**\AppData\Local\enthought\Canopy\User\Scripts\python.exe %1
However, with this the behavior remained the same. The above turned out to be half of the solution.
Fortunately, I was able to get it working using regedit. I had to edit Computer\HKEY_CLASSES_ROOT.py by changing the default from "Enthought.Canopy" to "Python.File". And I also changed Computer\HKEY_CLASSES_ROOT.py\OpenWithProgIds by deleting the "Enthought.Canopy" key and adding a "Python.File" key.
I'm really happy to have it working, however mucking around with regedit is a difficult task for Windows users of my software. Now I'm wondering, is there a simpler way to do this, perhaps in the install script that puts my folder of command-line scripts into their path? Any ideas are appreciated.
Sorry for the confusion -- "EPD-like" refers to running python directly, not to the windows file associations, but I can definitely see your point. Here's how to get what you want:
1) Even if you are a full admin on this system, open an "Administrator:Command Prompt" window as described in in steps 1 and 2 in this article: https://support.enthought.com/entries/23736288-Windows-On-some-systems-admin-users-cannot-immediately-install-for-all-users-
2) In this window, type the following command at the command prompt:
ftype Python.File=c:\Users\**\AppData\Local\enthought\Canopy\User\Scripts\python.exe %1
Test that it now works as desired, then close this window.

Default Folder for Terminal in OSX, When Running Python Interactive Shell

This is a follow up question as I'm trying to move forward with Zelle's Python:Programming.
It appears that IDLE 2.7.2 has hang issues when opening graphics windows in interactive mode. But, I can simply run Python interactively in Terminal and don't have any of those issues. So that's a big help. Zelle provides a simplified graphics file called graphics.py, to get up to speed with objects and graphics, before dealing directly with Tkinter.
My question is this. Where should I put graphics.py, so Terminal will see it (when it's called), without including the full path every time? Thanks,
Henry
According to PEP 0370, a good place to put your user packages is in ~/.local/lib/python2.7/site-packages.
Modules in here should be importable.
You can modify your ~/.bashrc to include a PYTHONPATH definition that includes the location of the file.
export PYTHONPATH="/path/to/directory_containing_graphics.py"
Just be careful if it's in your home director to use /Users/[username]/etc/directory_containing_graphics.py, I vaguely recall being bitten by ~ not expanding like I expected one time on OS X.
I went deep down the rabbit hole to get to bottom of this issue. It turns out that bash on OSX has a few quirks, not unexpected with the various flavors of UNIX around. It turns out that when firing up a bash shell, bash looks in .bash_profile for config statements. If you enter bash into bash, you fire up a sub shell, and that's when and only when .bashrc is executed.
To make sure you only have to manage one config file, put:
if [ -f ~/.bashrc ]; then
source ~/.bashrc
fi
in your .bash_profile. This just tells bash to look into the .bashrc file if it exists. You can then leave that file alone and only modify your .bashrc file and all instances of bash will be modified the same. Once I figured this out, I still had to solve my problem. Here's the best I could do. When Python installed it installed this into my .bash_profile:
PATH="/Library/Frameworks/Python.framework/Versions/2.7/bin:${PATH}"
export PATH
This tells bash where to look for the libraries needed to run Python. So I moved this statement to my .bashrc file after putting the "if" statement into my .bash_profile. I then tried adding a : to the PATH statement with the path to my Python modules, but that didn't work. So, I have settled for a statement like this in .bashrc:
PYTHONPATH=$PYTHONPATH:/Users/ftpbub/Documents/workspace/Python\ Programming\ Modules/src/
export PYTHONPATH
Now I enter python at the command prompt, and when I get to python, I can enter import modulename without the path and it works. If I start a new project in a new directory, I should be able to add it to my PYTHONPATH and be good. I would have liked to be able to enter python modulename right into bash and have the module execute, but I haven't figured out how to do that. Other than that, I think this the best I can do. Ideas for how to go straight to the module from the bash prompt, without entering the path?

starting Python IDLE from command line to edit scripts

I've tried many variations of this command: idle.py -e filepath, but it simply starts IDLE like normal, not opening any extra windows for editing, and not throwing any errors.
So how can I do the equivalent of opening IDLE, file>open>filepath via the command line (or perhaps even a Python module)?
You need to do as stated in the main.py file of the idelib folder (C:\Python33\Lib\idlelib), at least on the python 3.3 version explains that:
IDLE main entry point
Run IDLE as python -m idlelib
So with python -m idlelib <script_to_edit> you will be able to open and edit the script with idle. I haven't checked with previous versions but it could be the same comand
This is also documented on the changelog of the version 3.3.3
Make a new text file, and put something like this in it:
C:\Python26\Lib\idlelib\idle.pyw "C:\file1.py" "C:\file2.py"
In your actual script, you'll replace "C:\file1.py" and "C:\file2.py" with your files' paths, save as a .bat, and then launch it. That should do what you want.
Please forgive me for bumping such an old thread, but I've been teaching myself linux and python with the help of the community, and was trying to figure out how to invoke IDLE2 and IDLE3 from the command line. I came across this post some of the solutions seemed a bit complicated for my application. Then it occurred to me that I could just put syslinks in the /usr/bin/ path for each.
sudo ln -s idle-python3.1 idle3
sudo ln -s idle-python2.6 idle2
to address the OP. From the directory the script is located, type:
idle3 abc123.py
or
idle2 abc123.py
I'm just so damned happy that I finally had a "light bulb" go off that I wasn't going to let a 2 year old post stop me from posting my solution.
Rarely the native os is useful. I created a 'win batch file, in the folder with my .py files:
start /MIN cmd /C c:\Python27\lib\idlelib\idle.py -e %1 %2 %3 %4 %5 %6
This can open up to six files from cmd line in one shot. Just type the name of the batch file, followed by from zero to six filenames. Also if one or more files you specify are not found, idle opens these as new document(s).
first make sure you have location of idle in path
I am using "python3.5".So mine looks like this:
C:\Program Files\Python35\Lib\idlelib.Yours may differ.
use this following command:idle -r file_name.py to run the file
or just idle file_name.py to edit
or start idle -r file_name.py ^&exit
you can just program in Python to edit your Python files. A simple example. say you want to search for a word and then replace it with something else.
import fileinput
import os
os.chdir( os.path.join("c:\\","path") )
for file in os.listdir("."):
for line in fileinput.input(file,inplace=0):
if "search word" in line :
line=line.replace("search word","new word")
print line
(use inplace=1 to do in place editing.). Then save and run the script as normal Python script using the interpreter.
Just add IDLE's path to your PATH environment variable.
For example I created an environment variable called IDLE_PATH and set the value to C:\Python27\Lib\idlelib
Then in my PATH variable I added ;%IDLE_PATH%; and open a new cmd prompt or in console2 just open a new tab and run idle <file_name> to open the file, you will be able to do this from any directory. In IPython console add an ! before the command, for example !idle test.py.
Congrates, Now you're a python pimp!
paste the idlelib to your system path or user path, environment variable.for example, like this
C:\Program Files\Python310\Lib\idlelib
then type idle in your command prompt. done.

Categories