I am trying to make a Python script on my Mac (MacOS 10.14.6 Mojave) and I am getting trouble with installing a module (watchdog). I have the built-in Python 2 and I installed Python 3 with Homebrew.
If a type in the terminal python, I get:
Python 2.7.16 (default, Oct 16 2019, 00:34:56)
[GCC 4.2.1 Compatible Apple LLVM 10.0.1 (clang-1001.0.37.14)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
So Python 2 correctly uses GCC (the one provided by Apple? I am not sure) instead of Clang. Now, if I do python -m pip install watchdog it just works. But I want to install the module on Python 3, that for some reason uses Clang instead of GCC. In fact, if I type `python3', I get:
Python 3.8.0 (v3.8.0:fa919fdf25, Oct 14 2019, 10:23:27)
[Clang 6.0 (clang-600.0.57)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
I assume that as a consequence python3 -m pip install watchdog gives a compile error because Python 3 is not using GCC. The error message is very long and can be found here: https://pastebin.com/DEAKANQ9
In my $PATH I have /usr/local/bin (where gcc is installed) before /usr/bin, i.e.
echo $PATH
/Library/Frameworks/Python.framework/Versions/3.8/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Library/TeX/texbin:/opt/X11/bin
I would say everything is set up correctly, but apparently that is not the case. How can I make Python 3 use GCC instead of Clang?
I have fixed the issue.
First, I have removed Python 3.8 which was installed using the pkg installer (by accident actually). Then, I have created an alias for Python 3 in the .bash_profile. Another mistake was that I created the file ~/.bashrc (as in Ubuntu) instead of editing the file ~/.bash_profile to modify the $PATH.
# ~/.bash_profile
#
# Python alias
alias python=/usr/local/bin/python3
# Setting PATH for Python 3.7.5 (Homebrew)
PATH="/usr/local/bin:${PATH}"
export PATH
# Set module path
PYTHONPATH=$PYTHONPATH:/usr/local/lib/python3.7/site-packages
# Set PATH priority to Homebrew installation folder
export PATH=/usr/local/bin:/usr/local/sbin:$PATH
With this settings, I was able to install the module and make it work in my script!
Related
Yesterday, I did put my laptop on upgrade 19.10 to 20.04 but due to power failure, that became a partial-upgrade, the system broked. I resolved everything but my Django app wasn't running due to PYTHONPPATH so I tried uninstalling python3 and everything got broken. I re-installed that again.
Now when I do python --version I got
bash: python: command not found
whereas python3 --version gives correct answer.
Python 3.8.2
I have python2.7 and python3 both installed. So for now, my Python is not working and also I think I've messed up my PYTHONPATH and I really don't know what I'm going to do now.
My ./~bashrc file looks like below :
# Install Ruby Gems to ~/gems
export GEM_HOME=$HOME/gems
export PATH=$HOME/gems/bin:$PATH
# Install Ruby Gems to ~/gems
export GEM_HOME=$HOME/gems
export PATH=$HOME/gems/bin:$PATH
# Install Ruby Gems to ~/gems
export GEM_HOME="$HOME/gems"
export PATH="$HOME/gems/bin:$PATH"
I'm using Ubuntu 20.04.
Please specify how are you running your project and what exactly is the issue you are facing. May be you can paste the error message you get.
For python command,
In Linux, generally the base commands (like python) without version in it, would actually be pointing the specific (python) version executable through symbolic links (or simply links).
[foo#linuxbox ~]$ ls -l /usr/bin/python
lrwxrwxrwx. 1 root root 16 Feb 9 16:26 /usr/bin/python -> /usr/bin/python3
These links can be created or even edited to our need to point to the version we need. Use the below command to link python to python3. This is equivalent to setting alias for python3 as python but bit more than that as all users/process can run python but in case of alias the tool/user must be running from bash or corresponding shell where alias was created.
sudo ln -f -s /usr/bin/python3 /usr/bin/python
I feel in Ubuntu 20 you have to run command python2 to go into 2.7.* interpreter. python and python3 command both refers to Python3. But anyway your python command should work.
#ideapad:~$ python
Python 3.6.9 (default, Apr 18 2020, 01:56:04)
[GCC 8.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> exit()
ideapad:~$ python2
Python 2.7.17 (default, Apr 15 2020, 17:20:14)
[GCC 7.5.0] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> exit()
ideapad:~$ python3
Python 3.6.9 (default, Apr 18 2020, 01:56:04)
[GCC 8.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>>
To solve your issue, use an alias. Place command alias python=python3 into ~/.bashrc file, after adding this run source ~/.bashrc.
Other solutions:
run command which python it will reveal the location of installed Python and then try adding the location given by which python command to PYTHONPATH
Reinstall your python - sudo apt install python
When I run python3 in terminal, it states that I am running Python 2.7.10. I updated a pip package and conda package and since I have no way of running python3. I am sure python 2 is running as writing 'print "hello"' works which is should not, if python3 successfully ran.
Daves-MBP:Desktop dave$ python3
Python 2.7.10 (default, Oct 6 2017, 22:29:07)
[GCC 4.2.1 Compatible Apple LLVM 9.0.0 (clang-900.0.31)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> print "hello"
hello
This should NOT work if python3 is running.
How can I get python3 running when I want to?
Do I need to set up the environment path, or something else?
Good news. I have solved the problem myself (using a different forum article)
Setting the alias to the different python version in terminal solves this error.
$ alias python='python3.7'
$ alias python2='python2'
$ alias python3='python3.7'
So when I type 'python' in terminal, python3 is called. Not sure if my issue was an alias or path issue, as I was not aware of both concepts before I had the problem.
Make sure you have the python version installed before typing in python3.7 or 3.5 for instance.
Also, python3 alone does not work.
Type python3.1 or python3.3
OSX. When I installed the Canopy IDE, Enthought Canopy Python 2.7.6 was set as the default Python for the bash shell:
$ python
Enthought Canopy Python 2.7.6 | 32-bit | (default, Sep 15 2014, 17:36:57)
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>>
Currently, I am using another IDE (PyCharm) for a project where a Python module is needed. I tried to download the module directly from the bash shell using pip but it did not work:
pip install psycopg2 <---module
I believe it has something to do with Enthought Canopy Python running, so I attempted to restore the original python. However, I could not restore it. The instructions from this Enthought post (2011) did not work:
OS X - After EPD installation, restore system python to be default
They say to comment out the following lines from the ~/.bash_profile file, save the changes and restart the bash shell:
# PATH="/Library/Frameworks/Python.framework/Versions/Current/bin:${PATH}"
# export PATH
Didn't work.
All seems to work just fine for both python 2 and 3:
$ which Python
/Library/Frameworks/Python.framework/Versions/2.7/bin/python
$ python --version
Python 2.7.9
$ python2
Python 2.7.9 (v2.7.9:648dcafa7e5f, Dec 10 2014, 10:10:46)
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
$ python3
Python 3.4.3 (v3.4.3:9b73f1c3e601, Feb 23 2015, 02:52:03)
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
My .bash_profile settings are as follows:
PATH="/Library/Frameworks/Python.framework/Versions/2.7/bin:${PATH}"
export PATH
PATH="/Library/Frameworks/Python.framework/Versions/3.4/bin:${PATH}"
export PATH
The problem:
$ virtualenv My_Env
-bash: /usr/local/bin/virtualenv: /usr/local/opt/python3/bin/python3.4: bad interpreter: No such file or directory
The path above does not exist. I downloaded my python packages directly from the python site and installed using the default settings.
Prior to this, I used Python installed with HomeBrew, but this path does not appear to be a brew file path anyway.
Bottom line... My file path is messed up somewhere other than in my .bash_profile and I have no idea where to look to fix it.
Also note that I set up my other computer with the same exact .bash_profile and python installations and it works perfectly...
Both are running Mac Yosemite.
Thanks in advance!
Ok, I was able to fix the problem with a fresh install of virtualenv. I assume that is where the path issue was located (somewhere in the installation of virtualenv).
My problem was as simple as having spaces in the directory at the top of venv/bin/pip which meant that the path was inside quotes. As soon as I made sure that it wasn't under a directory with spaces and removed the quotes it worked.
eg. #!"/Users/Tomm/MY PROJECT/venv/bin/python" should be changed to #!/Users/Tomm/MY-PROJECT/venv/bin/python
You can check the "activate" file in your virtualenv bin folder, and see what is written there at around line 42, and then can actually manually set it, while keeping in mind that all the executables in this bin folder are hard coded for the first shebang line.
You will need to change them as well. Or just move the folder to the right place for you current temporary task, otherwise you might need a virtualenv relocation tool or just re-install it.
Re-installing virtualenv should solve this. I also went through same bug and reinstalling using pip solved this for me.
I am installing modules with homebrew and other installers, and they are not recognized by my default python. Module installations with easy_install (such as pip) appear to be available for my system and system python).
My default python is located here and is this version:
15:49 [~]: which python
/usr/local/bin/python
15:49 [~]: python -d
Python 2.7.2 (default, Mar 18 2012, 15:13:08)
[GCC 4.2.1 (Apple Inc. build 5577)] on darwin Type "help",
"copyright", "credits" or "license" for more information.
The packages do appear to be located in /library/frameworks/, GEOS.framework is one example.
What do I need to modify to gain access to my modules?
System: Mac os x 10.5.8
From the Homebrew page: "Homebrew installs packages into their own isolated prefix and then symlinks everything into /usr/local"
I think that the OS X preinstalled python looks for modules in
/Library/Frameworks/Python.framework/Versions/Current//lib/python2.7/site-packages
So maybe you need to symlink your Homebrew installed packages to there.