OSX Anaconda default python - python

I have anaconda distribution installed on my macbook to my local home directory /Users/simon/anaconda
When I open up iterm and type python I see the default OSX install of python. I saw this thread here and implemented the fix mentioned: Mac using default Python despite Anaconda install
My .bash_profile currently looks like this:
export PATH="$HOME/anaconda/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:$PATH"
A few strange things happen:
When I type python I still see the OSX python despite having changed my .bash_profile
If I source /Users/simon/.bash_profile this actually fixes the problem. Using python now brings up anaconda's python
When I quit iterm or restart my computer and try to load python again, it goes back to the OSX version. .bash_profile remains unchanged.
When I try all of the above using terminal everything works fine. The issues described above appear to be specific to iterm2 and I'm not sure why
How do I get my system to use anacondas python instead of the OSX version?

It seems that your $PATH is redefined somewhere else in your configuration. This usually doesn't cause issue if you know in which order they are loaded and keep track of what's going on.
I recommend a bit of reading to understand more the load order.

Related

Python not found

I'm working on a project in a python virtual environment, the project was started on a pc with python 3.8 installed and consequently python 3.8 was used in the virtual environment, or I had the need to continue the project on another pc, so I loaded all on GitHub, in the end I downloaded it to another PC with python 3.11 installed, the files are all there but when I try, inside the virtual environment, to open python by writing python or python3 in the terminal, it shows up this error: Python not found; Run with no arguments to install from the Microsoft Store or disable the link from Settings > Manage apps Run aliases. I then tried to see if it only showed up inside the virtual environment, but the same thing happens outside as well.
I tried to do various things among those suggested in other forums but they didn't work, the problem persists, I'm a bit lost, it's the first time this has happened to me.
Sorry to bother, maybe it's the simplest problem there is to solve but I don't know where to start
Trhanks
The problem is the different version of python on the two computers... the content of the pyvenv.cfg file must simply be changed which, when creating the virtual environment, is based on the installed version. Here you just need to change the path to reach the python.exe file installed on your computer and then change its version by inserting the correct one.

Can no longer access debugger in BBEdit virtual environment on MacOS Catalina

I upgraded to Catalina today, which required updating BBEdit as well. Now I am having trouble using my virtual environment, specifically the debugger in BBEdit.
I installed python3 in a virtual environment via Homebrew, set the correct path, and can access the virtualenv correctly via:
cd /Users/joecat/venvjc
source /Users/joecat/venvjc/bin/activate
I used pip3 to install modules needed
I am trying to run this test script:
#!/Users/joecat/venvjc/bin/python3
import pandas
print('hi')
The pandas module is only in the virtual environment so it should work. If I "Run in Terminal" through BBEdit, the code executes:
But when I try to run in debugger via Command+D, the code executes without the "pdb" debugger popping up at all:
Then, if I adjust the first line to be a "fake" path (assuming this just skips it) it correctly opens up the debugger, and pandas can't be imported because it's no longer using the virtualenv, which is correct:
#!/Users/joecat/venvdddddjc/bin/python3
import pandas
print('hi')
What am I doing wrong with respect to changes to Catalina/BBEdit? I switched to using zsh over bash... is that part of the problem? I am a newbie and happy to provide more details if needed. Thanks for any help anyone can provide.
There have been a lot of changes over time to how BBEdit interacts with the shell environment. As of 13.0.4, BBEdit will run your login shell to capture its environment, whenever you run a #! script. But there are special cases for Python, Ruby, and Perl, since those all have built-in support in BBEdit.
One thing to be aware of: if you've switched to zsh from bash, a common practice is to copy your bash environment from .bash_profile to .zshrc. This won't work correctly in BBEdit, because the shell that BBEdit runs is not an interactive shell.
For that reason, you should set up the majority (and perhaps all) of your zsh environment by putting the declarations (PATH, etc) in either .zprofile or .zshenv (but not both). Any interactive stuff can remain in .zshrc.
(And if you're still stuck, writing to support#barebones.com is always a good idea.)
(p.s. I would not recommend using any BBEdit version older than 13.0.4 on Catalina.)
I was able to correct the issue by downgrading to BBEdit 12.1.16, the earliest release that works with Catalina, as opposed to the latest version 13.0.2 that I was using.
This may be a bug in BBEdit, or else there's something else that changed this functionality between 12 and 13.
Would love to learn more if anyone has any information on this issue. Google is turning up next to nothing on this problem
In case it is helpful to anyone who comes across this issue, I was able to resolve this by importing and setting trace on the pdb module in lines 2 and 3 (right after the virtual environment path set on line 1):
import pdb
pdb.set_trace()
This allows the debugger to run normally in BBEdit 14.1.2, macOS Monterey 12.3.1.
No idea what the underlying issue is. I guess pdb is naturally imported when using the native OS python, but must be manually imported when using a virtual environment.
Hope this helps.

Why won't PyCharm see my libraries?

If I do something like "import selenium" (or any other kind of third party library) in a .py file and then run it from the terminal, it works just fine. But if I make a new file in PyCharm CE and do the same thing, it can't find the library / module.
How can I fix this or get it to point in the right location? I use a Macbook Pro.
You need to setup your project in PyCharm to use the Python interpreter that has your libraries:
Go to: file->settings->project->project interpreter
And select the appropriate interpreter from the dropdown. After selecting an interpreter, the window displays a list of libraries installed on that interpreter; this should further help you make the right selection.
I've faced a similar issue on Pop!_OS after installing PyCharm via Flatpak. I think the installation is somehow incomplete, as I've had these issues (among others):
Installer could not create the menu shortcut due to the lack of credentials. Unlike during a typical installation, it wouldn't ask for the password and instead I had to uncheck that option altogether.
Built-in terminal defaulted to sh. Even after changing to bash, it would not read my .bashrc and many commands were missing.
After changing the interpreter into a local virtualenv, it would just default to Python 3.7 (even though the version was actually 3.8) and it didn't see any of my installed libraries.
When I've tried to use a Docker Compose environment, IDE failed to detect Docker Compose installation.
I've eventually uninstalled PyCharm and downloaded it directly from Jetbrains website to make it work correctly.

Will installing Anaconda3 change Mac OS X default Python version to 3.4?

I'm planning to install Anaconda3 for Python 3.4. Since by default, Mac OS X uses Python2, will install Anaconda3 change the default Python version for the system? I don't want that to happen since Python3 can break backwards compatibility. If it does change the default Python version, how can I avoid that?
Apple has a built-in system for managing multiple versions of software, and switching between them. But you don't even need to worry about that, because Anaconda installations are self-contained: Everything lives under the top Anaconda installation directory (probably /Applications/anaconda). The only effect outside this directory is that during installation, Anaconda will offer to modify the PATH variable in your .bashrc. If you agree, it will add one line at the end of your .bashrc, something like this:
PATH="/Applications/anaconda/bin:$PATH"
As you can see, Anaconda puts itself first in the system path. This means that typing python at the shell prompt will launch python 3, which may not be what you want. I run Anaconda 3.4 like this and have had absolutely no problems with my system, but I did need to modify my own executable python2 scripts that launched python like this:
#!/usr/bin/env python
This is a nice way to find python wherever it is, but in this case it will find python 3-- oops! Changing the above to #!/usr/bin/python or to #!/usr/bin/env python2 ensures that they continue to work correctly. In my experience this was not necessary with any of the system's own scripts; everything is already set up to find the right python.
Alternative 1: You could decline the PATH modification, and use Anaconda via the launcher. In that case there is no change to the rest of your execution environment. The launcher will start a special bash prompt with the anaconda environment activated, but execution in normal shells is completely unaffected. If you will continue to program a lot in python 2, this may be for you.
Alternative 2: A minimal-impact alternative is to put the anaconda directory last in your path:
PATH="$PATH:/Applications/anaconda/bin"
This ensures that non-anaconda binaries take precedence over anaconda, so python will start good old /usr/bin/python (that is, python 2). You can start anaconda's variant by typing python3, idle3, etc. I did not have IPython before I installed anaconda, so typing ipython finds the anaconda version.
No it won't, you can have multiple python installs, once you don't remove your system python or manually change the default you will be fine.

How to completely uninstall Python 2.7 from Windows 7 PC

Having installed Python 2.7 from here:
https://www.python.org/downloads/release/python-279/
I then uninstalled it using the control panel (I have Windows 7 pro). Now Python 2.7 no longer appears in the list of installed programs, however the files are still sitting in the same place on the C: drive.
I have since installed version 2.6 but I seem to be having some clashing issues between the versions. I'm having similar issues to this guy:
How to completely remove Python from a Windows machine?
I just want to know how can I remove Python 2.7 completely?
Will simply deleting the folders from my C: drive be sufficient?
How can I test that it has been completely removed?
You should just be able to delete the local files if you've already uninstalled from control panel. Also be sure to go to your environment variables and make sure that the python 2.7 directory isn't there. To do that,
Go to the start menu and right click on Computer
Click on Properties
Advanced system settings
Environment Variables and look for "path" under system variables
Be sure to erase C:\...\Python2.7.x
If you uninstalled from control panel it might not be there but it's probably good to double check. Also, be sure to delete the ; before C:\...\Python2.7.x
I had a similar problem. I kept installing Python 3.6 but when I typed "python" from the command prompt, Python 2.7 kept opening up despite the fact that I had uninstalled and it wasn't in my Path or in my Programs folder. I eventually solved the problem by uninstalling Enthought/Canopy from my computer and also erasing all the related files. Now I have a regular installation of Python 3.6 working and accessible from the command prompt. I assume I could now also get a parallel python 2.7 going, but I haven't tried to since I have no need for it at the moment.
The giveaway for me that my python 2.7 installation was strange was that when I typed:
python --version
into the command prompt, I was getting the following:
Python 2.7.6 -- CUSTOM

Categories