I have an issue where somewhere along the line i've installed python3 and it has overwritten the default python path which is for 2.7. So when I go to terminal and type in "python" it loads version 3.6.5 instead of 2.7. If i type in "python2.7 to explicitly run python i get an error saying its pointing to the 3.6 site-packages instead of 2.7.
derekchan#PandaMacPro:~/python$ python2.7
Your PYTHONPATH points to a site-packages dir for Python 3.x but you are
running Python 2.x!
PYTHONPATH is currently: "/usr/local/lib/python3.6/site-packages"
You should unset PYTHONPATH to fix this.
I've viewed other threads on this issue but it doesnt solve or help my problem. Is this a simple PYTHONPATH issue?
I just want to be able to type in "python" and it load version 2.7 instead of version 3 and not have issue with the conflicting python packages.
Consider using a distribution like Anaconda with built-in package management. With Anaconda you can easily isolate your Python2 and Python3 environments and not have to mess with PYTHONPATH
https://anaconda.org/
Related
Every time I try to run % brew list python it returns Error: No such keg: /opt/homebrew/Cellar/python#3.9. I think this is because I used python 3.9 up until recently - I uninstalled it and instead installed python 3.8 using homebrew. I removed all references of python 3.9 from /usr/local/bin, but still get that error when I run brew list python. Running % env returns this path: PATH=/opt/homebrew/opt/python#3.8/bin:/Library/Frameworks/Python.framework/Versions/3.8/bin:/opt/homebrew/bin:/opt/homebrew/sbin:/Library/Frameworks/Python.framework/Versions/3.9/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Library/Apple/usr/bin which doesn't make any sense. Why does python 3.8 have references to python 3.9? I think this is the cause of my brew list python issue. How can I fix this?
When you first installed 3.9, homebrew added the 3.9 directory to your PATH environment variable in one of your shell startup files.
Installing 3.8 didn't remove this, it just added the 3.8 directories ahead of it.
Look for this in your startup scripts (the specific script depends on your shell, it could be .bashrc, .zshrc, .profile, or something similar) and remove the 3.9 directories that you don't need any more.
Or just ignore it, since the 3.8 directory is first, so it will take precedence.
I have just installed homebrew and I have installed Python 3.7.5, although if I enter python --version, it tells me I have 3.6.4
If I use brew info python, it tells me I have Python 3.7.5, but a number of warnings appear. This includes unbrewed dylibs, some config files found outside my system or homebrew directories, as well as unbrewed header files, unbrewed .pc files and unbrewed static static libraries.
Running which python gives me /usr/bin/python
Echo $PATH gives me /Library/Frameworks/Python.framework/Versions/3.6/bin:/anaconda3/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/X11/bin
This is the result, I think of a previous Anaconda installation.
I want to start from scratch with a clean version of Python using homebrew.
What should I do? Any help is appreciated please.
Edit the file ~/.bash_profile and set your PATH environment variable to:
/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/X11/bin
I haven't used Python in a while, and only in Linux. Now on Windows, and just installed 3.7.4. I noticed immediately that python3.exe is not in the install directory, nor any of the pythonX.x.exe files, that are used for compatibility. I can only access Python through "python" from my command prompt, and old scripts that use Python 3 won't work.
Is there something I am missing here?
Of course, I can solve this for now by using symlinks, but is this an error in 3.7.4, or more likely, have I done something wrong in setting up my environment on Windows?
No, there's nothing wrong. This is just how Python is on Windows. There's the py launcher too that might help you out here.
https://docs.python.org/3/using/windows.html
3.2 The Microsoft Store Package
All three commands are also available with version number suffixes, for example, as python3.exe and python3.x.exe as well as python.exe (where 3.x is the specific version you want to launch, such as 3.7).
Virtual environments can be created with python -m venv and activated and used as normal.
If you have installed another version of Python and added it to your PATH variable, it will be available as python.exe rather than the one from the Microsoft Store. To access the new installation, use python3.exe or python3.x.exe.
So I downloaded a module, but when I tried to use it in a program, Python threw the error:
"ImportError: No module named markovify"
When I go to try to change my .bash_profile, it shows this:
"# Setting PATH for Python 3.5
The orginal version is saved in .bash_profile.pysave
PATH="/Library/Frameworks/Python.framework/Versions/3.5/bin:${PATH}"
export PATH"
I've been using 2.7.10 all this time, and Terminal defaults to it. (When I type in Python, that's the version it says I'm using)
I'm trying to get pip to install modules for python 2.7.10 to a different folder.
What's weird is this: I seem to have installed pyparsing with pip and it seems to work. I tried installing markovify and it throws this error message.
What am I missing?
When I go to try to change my .bash_profile, it prints this
That suggests you're using some tool to change your profile. Did you also use that tool to install markovify? You need to be clear about your environment when you have environment questions! :-)
If you installed markovify from the command line, I'd suggest opening a new terminal and running these commands, just to make sure you're working from where you think you are:
$ python --version
Python 2.7.10
$ command -v python
/usr/bin/python
The most likely problem, it seems to me, is that you got a bit tangled up and wound up doing something other than what you intended. From a fresh start, provided you're starting with the environment you want, pip should, you know, Just Work.
I'm trying to get pip to install modules for python 2.7.10 to a different folder.
That's possible to do, but are you sure that's what you want? Usually if you're using the Python interpreter you intend to, and haven't putzed with PYTHON_PATH & friends, when you run pip, it will install to its default location, which sure enough is where Python will look for it when you say to import it.
As an experiment, you might check if markovify was somehow installed for Python 3.5. Try
$ /Library/Frameworks/Python.framework/Versions/3.5/bin/python -c 'import markovify'
(You might also want to check that the Python interpreter is in fact in that folder and has that name.)
When you're working on more than one Python version, you should work on Virtual Environments:
Virtual Env on Hitchhiker's Guide
I'd like to use either python 3.4 installation standard and Anaconda with python 3.4 in the same Computer. But when I make a standard installation of a new module or python installation (for example pip install Django) all is right in anaconda environment but it doesn't work in the python 3.4 standard environment. My OS is Windows 7 and I'd like a solution not like sys.path.append() which I should execute everytime I start Python 3.4 standard version
I have found a solution or better I learn a thing I did not know. For installing a module in the python 3.4 installation I should use per specif pip3.4.exe file which is in the directory scripts in the python 3.4 installation and not the "general" pip.exe file which install all the modules in the python 3.4 anaconda installation, which is considered the default one.
You can set both site-packages directories in the PYTHONPATH environment variable, or write a pth file (see https://docs.python.org/2/library/site.html) that imports one into the other. Just a warning though that this can get messy fast.