I'm currently using mac and whenever, I'm launching the terminal it will show like code below. I tried all the method in stackoverflow but it didnt work, so I'm posting my own. Please help me to fix this. I had tried "sudo apt-get install python3-pip" or "sudo pip3 install virtualenvwrapper". They are all installed
Error Message
Last login: Tue Aug 18 22:33:59 on ttys000
virtualenvwrapper_run_hook:12: no such file or directory: /usr/local/bin/python3
virtualenvwrapper.sh: There was a problem running the initialization hooks.
If Python could not import the module virtualenvwrapper.hook_loader,
check that virtualenvwrapper has been installed for
VIRTUALENVWRAPPER_PYTHON=/usr/local/bin/python3 and that PATH is
set properly.
Which python command
/usr/bin/python
Python version command
Python 2.7.16
Which python3 command
/Library/Frameworks/Python.framework/Versions/3.7/bin/python3
Python version3 command
Python 3.7.4
pip3 --version command
pip 19.3.1 from /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pip (python 3.7)
Related
I am trying to execute a python script that needs img2pdf module.
Note, I already have the Ubuntu package installed for python-img2pdf:
which img2pdf
/usr/bin/img2pdf
Given the following line:
import img2pdf
I get the following:
ModuleNotFoundError: No module named 'img2pdf'
I had only python3.6 version installed before and I have installed python3.9.1 now, After that, I have started getting this error. I think it is something to do with PATH or python default version but after a lot of efforts, I am unable to rectify it.
These are my system details which might help you understand my problem further.
$python -V
Python 3.6.9
$python3 -V
Python 3.9.1
$pip -V
pip 21.0.1 from /usr/local/lib/python3.9/site-packages/pip (python 3.9)
$which python
/usr/bin/python
$which python3
/usr/local/bin/python3
$which pip
/usr/local/bin/pip
Ubuntu 18.04.4
Arm64 arch
Try something like this, I think img2pdf is a shell cmd and cannot be used as a python module ^^
Best regards
deleaf
import os
img2pdf = os.system("img2pdf /path/to/your/image")
https://stackabuse.com/executing-shell-commands-with-python/
I have followed the instructions at https://opensource.com/article/19/5/python-3-default-mac:
Now, python -V shows 3.8.1, but pip -V still shows 19.2.3.
I checked with which pip3, which shows
/Library/Frameworks/Python.framework/Versions/3.8/bin/pip3, but using
echo "alias pip=/Library/Frameworks/Python.framework/Versions/3.8/bin/pip3>> ~/.zshrc does not seem to work.
pip -V gives: pip 19.2.3 from /Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/pip (python 3.8).
I have MacOS Cataline 10.15.3. Can someone help please?
There seems nothing wrong with your setup. pip has a version number that is independent of that of python. Your python version is 3.8 and the corresponding pip (which resides in python3.8/site-packages/pip) has version 19.2.3. You have set up everything just fine
In fact I was trying to install python in pyenv and get my IDLE to work. The following worked for me (mostly from https://github.com/pyenv/pyenv/issues/1375; Installed Python 3 on Mac OS X but its still Python 2.7; https://opensource.com/article/19/5/python-3-default-mac, with a few additional steps). Thanks for your help. I posted my solution at https://github.com/pyenv/pyenv/issues/1375, too, for reference)
ran $brew install pyenv
ran $brew install tcl-tk
Output after "brew reinstall tcl-tk':
tcl-tk is keg-only, which means it was not symlinked into /usr/local,
because tk installs some X11 headers and macOS provides an (older) Tcl/Tk.
If you need to have tcl-tk first in your PATH run:
echo 'export PATH="/usr/local/opt/tcl-tk/bin:$PATH"' >> ~/.zshrc
(I added it to ~/.zshrc as the first line)
For compilers to find tcl-tk you may need to set:
export LDFLAGS="-L/usr/local/opt/tcl-tk/lib"
export CPPFLAGS="-I/usr/local/opt/tcl-tk/include"
(I added these two to ~/.zshrc, too, after adding the above)
For pkg-config to find tcl-tk you may need to set:
export PKG_CONFIG_PATH="/usr/local/opt/tcl-tk/lib/pkgconfig"
(I added this two to ~/.zshrc, too, after adding the above)
To get tcl-tk 8.6 to work with the pyenv install of python, I found:
/usr/local/Cellar/pyenv/1.2.13/plugins/python-build/bin/python-build
and replaced the following:
$CONFIGURE_OPTS ${!PACKAGE_CONFIGURE_OPTS} "${!PACKAGE_CONFIGURE_OPTS_ARRAY}" || return 1
with:
$CONFIGURE_OPTS --with-tcltk-includes='-I/usr/local/opt/tcl-tk/include' --with-tcltk-libs='-L/usr/local/opt/tcl-tk/lib -ltcl8.6 -ltk8.6' ${!PACKAGE_CONFIGURE_OPTS} "${!PACKAGE_CONFIGURE_OPTS_ARRAY}" || return 1
ran $pyenv install 3.8.1
Installed Python-3.8.1 to /Users/ryan/.pyenv/versions/3.8.1
ran $pyenv global 3.8.1
Refreshed the current terminal and checked
$pyenv version
output: 3.8.1 (set by /Users/ryan/.pyenv/version)
Ran $python -V
output: Python 3.8.1
ran $pip install --upgrade pip (since I had previously already installed pip using $pip install)
output: Successfully installed pip-20.0.2
Tested my tcl-tk installation with $python -m tkinter -c 'tkinter._test()'
Output: Tk window popped up. Hit ‘Quit’ to back to Terminal.
Ran $ idle
Output: Python 3.8.1 Shell window popped up.
The installation was done on a MacBook Pro with macOS Catalina 10.15.3.
I am new to python and ubuntu to be fair. I have been recently following a couple of tutorials and they use pylint to check the syntax of the python code.
I've installed it as normal through the terminal using 'sudo pip3 install pylint', however whenever I format in VS Code I get an error stating pylint does not exist, do I want to install. On the attempt to install, i get another error due to pip not existing.
I've looked in the terminal after attempting to reinstall pip and pylint, however it's going to the python3.6 folder and not python3.7 folder, hence the errors.
Any ideas on how to resolve this?
Pip output is currently: "pip 9.0.1 from /usr/lib/python3/dist-packages (python 3.6)"
If i try to install pylint via the terminal using "python3 -m pip install pylint", I get the output error of: "/usr/local/bin/python3: No module named pip"
After following stovfl's suggestions i realised that python 3 needed redirecting to the 3.7 install
I googled and found this article: http://ubuntuhandbook.org/index.php/2017/07/install-python-3-6-1-in-ubuntu-16-04-lts/
At step 3, it tells you how to makepython3 use the new install with the following command:
sudo update-alternatives --install /usr/local/bin/python3 python3 /usr/bin/python3.7 1
Now when I intall pip and pylint it directs to the new 3.7 folder. Meaning it also works as intended with VS Code.
I'm unable to import numpy in Python 2.7 in the shell. I installed Python with brew install, then numpy with sudo pip install. I tried without sudo but I get a permission denied error. Anyway, I get this:
ImportError: dlopen(/usr/local/Cellar/python/2.7.10_2/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload/_io.so, 2): Symbol not found: __PyErr_ReplaceException
Referenced from: /usr/local/Cellar/python/2.7.10_2/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload/_io.so
Expected in: flat namespace
in /usr/local/Cellar/python/2.7.10_2/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload/_io.so
In /usr/local/bin/ I have the following:
pip
pip2
pip2.7
pip3
pip3.4
And:
python
python-config
python2
python2-config
python2.7
python2.7-config
python3
python3-config
python3.4
python3.4-config
python3.4m
python3.4m-config
pythonw
pythonw2
pythonw2.7
The output of which python is /usr/local/bin/python
As for workaround, try downgrading your Python to 2.7.9 like:
brew switch python 2.7.9
by overriding the existing one, as it seems there is some particular problem with 2.7.10. Then re-link it again (if required).
Also make sure your PYTHONPATH is correct (you don't override it anywhere in your startup files).
That output is normal. Have you tried running brew install openssl followed by brew link --force openssl and then brew install python. The following thread helps describe the issue https://github.com/Homebrew/homebrew/issues/40516
I have searched online for a while for this question, and what I have done so far is
installed python32 in homebrew
changed my .bash_profile and added the following line to it:
export PATH=/usr/local/bin:/usr/local/sbin:~/bin:$PATH
but when I close the terminal and start again, I type 'which python', it still prints:
/usr/bin/python
and type 'python --version' still got:
Python 2.7.2
I also tried the following instruction:
brew link --overwrite python
or try to remove python installed by homebrew by running this instruction:
brew remove python
but both of the above two instructions lead to this error:
Error: No such keg: /usr/local/Cellar/python
can anybody help, thanks
brew install python or brew info python output mentions:
Unversioned symlinks python, python-config, pip etc. pointing to
python3, python3-config, pip3 etc., respectively, have been installed into
/opt/homebrew/opt/python#3.9/libexec/bin
So running
% echo 'export PATH=/opt/homebrew/opt/python#3.9/libexec/bin:$PATH' >> ~/.zprofile
% source ~/.zprofile
# For bash use ~/.bash_profile.
gets you those symlinks created by Homebrew - python=python3, pip=pip3 etc
% python --version
Python 3.9.10
% pip --version
pip 21.3.1 from /opt/homebrew/lib/python3.9/site-packages/pip (python 3.9)
If you want to install Python 3 using Homebrew:
$ brew install python3
==> Downloading http://python.org/ftp/python/3.3.0/Python-3.3.0.tar.bz2
Already downloaded: /Library/Caches/Homebrew/python3-3.3.0.tar.bz2
==> ./configure --prefix=/usr/local/Cellar/python3/3.3.0 --enable-ipv6 --datarootdir=/usr/local/Cell
==> make
==> make install PYTHONAPPSDIR=/usr/local/Cellar/python3/3.3.0
==> make frameworkinstallextras PYTHONAPPSDIR=/usr/local/Cellar/python3/3.3.0/share/python3
==> Downloading https://pypi.python.org/packages/source/d/distribute/distribute-0.6.35.tar.gz
Already downloaded: /Library/Caches/Homebrew/distribute-0.6.35.tar.gz
==> /usr/local/Cellar/python3/3.3.0/bin/python3.3 -s setup.py install --force --verbose --install-li
==> Downloading https://pypi.python.org/packages/source/p/pip/pip-1.3.1.tar.gz
Already downloaded: /Library/Caches/Homebrew/pip-1.3.1.tar.gz
==> /usr/local/Cellar/python3/3.3.0/bin/python3.3 -s setup.py install --force --verbose --install-li
==> Caveats
Homebrew's Python3 framework
/usr/local/Cellar/python3/3.3.0/Frameworks/Python.framework
Distribute and Pip have been installed. To update them
pip3 install --upgrade distribute
pip3 install --upgrade pip
To symlink "Idle 3" and the "Python Launcher 3" to ~/Applications
`brew linkapps`
You can install Python packages with
`pip3 install <your_favorite_package>`
They will install into the site-package directory
/usr/local/lib/python3.3/site-packages
Executable python scripts will be put in:
/usr/local/share/python3
so you may want to put "/usr/local/share/python3" in your PATH, too.
See: https://github.com/mxcl/homebrew/wiki/Homebrew-and-Python
Once installed update your system PATH variable, add the next line to ~/.bash_profile
export PATH=/usr/local/bin:/usr/local/sbin:~/bin:$PATH
And then:
$ source ~/.bash_profile
Now launch Python:
$ python3
Python 3.3.0 (default, Mar 26 2013, 10:01:40)
[GCC 4.2.1 Compatible Apple LLVM 4.2 (clang-425.0.27)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>>
You can check python3 path:
$ which python3
/usr/local/bin/python3
You may try adding this line to your .bash_profile
alias python='python3'
I came through the same issue and did some research. I found that someone has created a bug for the same issue under the azure/cli repository. You can find that issue here. I am providing the same solution here which was very easy and fixed my issue:
Most probably the Brew is broken and needs some patching or fixing. So run brew doctor command which will give you a summary about what is happening.
Below is what I got:
mymac:bin sidmishra$ brew doctor
Please note that these warnings are just used to help the Homebrew maintainers
with debugging if you file an issue. If everything you use Homebrew for is
working fine: please don't worry or file an issue; just ignore this. Thanks!
Warning: The following directories do not exist:
/usr/local/sbin
You should create these directories and change their ownership to your account.
sudo mkdir -p /usr/local/sbin
sudo chown -R $(whoami) /usr/local/sbin
Warning: Unbrewed dylibs were found in /usr/local/lib.
If you didn't put them there on purpose they could cause problems when
building Homebrew formulae, and may need to be deleted.
Unexpected dylibs:
/usr/local/lib/LibSideSyncOSX9.dylib
/usr/local/lib/ss_conn_lib.dylib
Warning: You have unlinked kegs in your Cellar
Leaving kegs unlinked can lead to build-trouble and cause brews that depend on
those kegs to fail to run properly once built. Run `brew link` on these:
python
The awesome stuff about the command brew doctor is that it not only tells you issues but also suggests you the solution steps in most of the cases.
So, I ran all the commands suggested by the brew and to link I ran the following command:
brew link python
Above command threw me an error:
mymac$ brew link python
Linking /usr/local/Cellar/python/3.7.1... Error: Permission denied # dir_s_mkdir - /usr/local/Frameworks/Python.framework
It seems that /urs/local/Frameworks doesn't have enough rights for my current user. So, I ran the following command and gave enough rights to my current user:
sudo chown -R $(whoami) /usr/local/Frameworks/
After running above command I ran linking command again, and it worked!!!
mymac$ brew link python
Linking /usr/local/Cellar/python/3.7.1... 1 symlinks created
Now run following command to get the current selected python version:
python --version
Above command should give you 3.7.1 (as of 21st Dec 2018) or new version for the python. There might be a chance that your Mac would have python2 set by default. If the version is not python3 then you have to a couple of steps to use the latest python3 over python2 version. Here are the steps:
Using Shell:
Open ~/.bash_loginor ~/.bash_profileor ~/.cshrcor ~/.profileor ~/.tcshrcor ~/.zprofile, whatever shell you are using for commands, in edit mode. You may have to use sudo to edit them.
Add following steps to it:
PATH="/Library/Frameworks/Python.framework/Versions/3.2/bin:${PATH}"
export PATH
Also, add following for backup:
alias python=python3
OR
Using homebrew:
Run following commands to unlink python2 and link python3:
mymac$ brew unlink python#2
mymac$ brew link python#3
Above will unlink python2 and link python3.
Hope some of you will get helped from this answer.
Good Day!!!
From $ brew info python:
This formula installs a python2 executable to /usr/local/bin.
If you wish to have this formula's python executable in your PATH then add
the following to ~/.bash_profile:
export PATH="/usr/local/opt/python/libexec/bin:$PATH"
Then confirm your python executable corresponds to the correct installation:
$ which python or
$ python --version
Installing with Homebrew is recommended on macOS. That being said, Python 2.7 comes with Mac OS; however, it is deprecated and will be removed soon. As such, you should be using Python3 and newer.
Install Homebrew.
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"
Run brew install python
Once Python is installed, Homebrew will say that the installation is complete, but that you already have Python 2.7 installed. This is nice, but we want to set it to actually see python3 as an option
Use brew link
Confirm by running which python3, the path should be /usr/local/bin/python3