I'm running Ubunutu 13.04. When using IPython, it points to a 3.3.1 copy of python that was installed in /usr/bin. I recently installed the most recent release of Python (3.3.2), which installed itself to /usr/local/bin. This means that typing 'python3' into the terminal, python3.3.2 comes up, but when I type 'ipython3', it uses 3.3.1.
I know this doesn't affect my programming (I'm not advanced of a user enough to make use of any of the differences between .1 and .2), but I'd still rather tidy my system up and use the most recent version. I tried using the fix given here, changing
#!/usr/bin/python3
to
#!/usr/local/bin/python3
But the following error is given:
Traceback (most recent call last):
File "/usr/bin/ipython3", line 5, in
from pkg_resources import load_entry_point
ImportError: No module named 'pkg_resources'
So the questions are:
1) How can I make python3.3.2 install over 3.3.1 (ie not in /local/)? I have no need for 3.3.1 once 3.3.2 is going.
2) How can I change IPython to point to python in /local/?
3) Which one of these options is better?
While this is certainly not a very neat solution, if you are really desperate, you can backup /usr/bin/python3 and use ln -s to create a link from /usr/bin/python3 to /usr/local/bin/python3, as such:
mv /usr/bin/python3 /usr/bin/python3-backup
ln -s /usr/local/bin/python3 /usr/bin/python3
(you might need to use sudo)
Be warned that this might mess up automated uninstalls et cetera, so rather use this as a temporary fix
Related
This is my first time asking on this site, so sorry if my question is not layed out correctly
y#DESKTOP-MQJ3NCT:~/Real-Time-Voice-Cloning$ python demo_toolbox.py
Traceback (most recent call last):
File "demo_toolbox.py", line 1, in <module>
from pathlib import Path
ImportError: No module named pathlib
I have tried:
pip3 install pathlib
and:
sudo -H pip3 install pathlib
but continue to get the same error
I am using the windows store version of ubuntu 18 LTS and python 3.7
When it comes to python, it's quite easy to make the mistake of just running "python ...". When you install python on windows "python" defaults to the python 2.7 installation ( probably changed now that 2.7 is no longer supported) if it is installed.
Ubuntu has the links "python2" and "python3" which makes so much more sense but can still lead to confusion.
If you have a local python Virtual environment, the "python" command defaults to the global install on windows (to further confuse people).
I find it generally best to create my own links to the global python "python27" and "python36" to avoid these confusions.
Same goes for pip. It's best to call
python3 -m pip install ...
Also. PyCharm is the most amazing Python IDE in the world and it helps with so much.
Sorry, turns out it was a simple mistake!
Instead of:
python demo_toolbox.py
I should have used
python3 demo_toolbox.py
As Linux defaults to Python 2 or something incompatible with pathlib
I am integrating gstreamer and pocketsphinx on mac using python 3.6; however, the first line of code, from gi import pygtkcompat, raises an error.
The command:
python3 demoapp_chinese.py
returns
Traceback (most recent call last):
File "demoapp_chinese.py", line 1, in
from gi import pygtkcompat
ModuleNotFoundError: No module named 'gi'
Here's how I install pygobject:
brew install pygobject3
And when I try to get more info. I execute
brew info pygobject3
which returns
pygobject3: stable 3.30.4 (bottled)
GNOME Python bindings (based on GObject Introspection)
https://wiki.gnome.org/Projects/PyGObject
/usr/local/Cellar/pygobject3/3.30.4 (69 files, 1.6MB) *
Poured from bottle on 2019-02-04 at 17:21:21
From: https://github.com/Homebrew/homebrew-core/blob/master/Formula/pygobject3.rb
(here I only post the first few couple of lines)
For the python info,
which python3
returns
/usr/local/bin/python3
Besides,
echo $PYTHONPATH
returns
/usr/local/lib/python3.6/site-packages
echo $PATH
returns
/Users/cindy/bin:/usr/local/bin/python3.6:/usr/local/lib/python3.6/site-packages:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Applications/VMware Fusion.app/Contents/Public
Lastly, I don't know if this is normal, when I run
which pygobject3
NOTHING returns on the terminal.
Please help, thanks. If you need any extra info. to help me, please let me know.
I have an issue with Python on my Mac with High Sierra.
After running pip install pysal, I have a successful installation. However, the module is not found when I run in python:
> import pysal
Traceback (most recent call last): File "<stdin>", line 1, in <module> ImportError: No module named pysal
I do not face such errors when running the same command in python2. However, most of my python scripts call the interpreter at the beginning of the file with #!/usr/bin/env python, so I would prefer not having to rely on python2 (I don't know how to do it either).
I figured out that this is python's executable is not on the same location where pip installs the modules:
macbook-pro-3:~ ME$ which -a python
/usr/bin/python
macbook-pro-3:~ ME$ which -a pip
/usr/local/bin/pip
I tried to follow the solution proposed by #J0ANMM in Modules are installed using pip on OSX but not found when importing . It recommeds downloading the script get-pip.py and executing it with sudo /usr/bin/python get-pip.py. I tried, but it did not change anything (the previous which commands still yield the same thing).
How do I manage to make pip work with my version of python?
Getting Python right on Mac seems a constant challenge. I'm working with a Homebrew implementation, and now have difficulty running Jupyter except with sudo:
$ which python
/usr/local/bin/python
$ which pip
/Users/username/bin/pip
$ which jupyter
/usr/local/bin/jupyter
$ jupyter notebook
Traceback (most recent call last):
File "/usr/local/bin/jupyter", line 7, in <module>
from jupyter_core.command import main
ImportError: No module named jupyter_core.command
$ sudo jupyter notebook
The Jupyter Notebook is running at: http://localhost:8888/
Once running, Jupyter fails to import pandas (installed via pip install pandas):
import pandas
ImportError Traceback (most recent call last)
<ipython-input-18-d6ac987968b6> in <module>()
----> 1 import pandas
ImportError: No module named pandas
.. even though pandas is available (python -s 'import pandas' works fine). Guessing its path isn't available to root.
I'm wondering if Jupyter is particularly problematic or if this is just my setup..?
Grateful for assistance as this is becoming very tiresome. Any guidance on wiping python and reinstalling 'properly' from scratch would be handy.
Edit:
$ which virtualenv
/usr/local/bin/virtualenv
21:16 $ virtualenv
Traceback (most recent call last):
File "/usr/local/bin/virtualenv", line 7, in <module>
from virtualenv import main
ImportError: No module named virtualenv
What python is in the shebang (#!) line on pip and jupyter? You may have installed jupyter with a pip that was using /usr/bin/python. Which means it's not there in the libraries installed for Homebrew's /usr/local/bin/python.
You should be able to resolve this with something like this:
/usr/local/bin/python $(type -p pip) install jupyter
But in general I second #Ray's suggestion of using pyenv to manage a personal set of Python installations that you can switch between, independently of what's on the system. (I likewise use rbenv for Ruby and perlbrew for Perl.)
Stop using python via native install on OSX or via homebrew right now!!!
First learn to use pyenv to control your version of python being used. Pyenv allows you to safely switch between any version of python you want at any time without messing up the natively installed python (which may be needed by the system): https://amaral.northwestern.edu/resources/guides/pyenv-tutorial
Second learn how to use virtual environments (pyvenv) to sandbox your projects. Virtual environments will allow you to have different sets of libraries installed by pip and such available as needed: https://robinwinslow.uk/2013/12/26/python-3-4-virtual-environment/
With these two technologies in your toolbox you will never have the issue you are experiencing again.
Please note pyvenv and pyenv are two seperate technologies used to enable similar goals (to control/sandbox environments) with unfortunately VERY similar names. One thing to note is you'll see older references to virtualenv if you google around a bit. This is the same thing as pyvenv.
Someone put together a good overview of using these with Jupyter: http://www.alfredo.motta.name/create-isolated-jupyter-ipython-kernels-with-pyenv-and-virtualenv/.
The other option is to do everything in virtual machines (with say virtualbox) or better still Docker containers, but this a whole other ball of fun best left to after you master virtual environments (you'll want them when you build your docker images anyhow).
Here is a post about installing a module in python3. When I use brew install python, then it installs it for 2.7.
When I use the method suggested by dan, which aimed to install it directly in python3 (who i really thank), but which didn't work :
# Figure out the path to python3
PY3DIR=`dirname $(which python3)`
# And /then/ install with brew. That will have it use python3 to get its path
PATH=$PY3DIR:$PATH brew install mapnik
The installation was successful but in python2. so I get:
For non-homebrew Python, you need to amend your PYTHONPATH like so: export PYTHONPATH=/usr/local/lib/python2.7/site-packages:$PYTHONPATH
so i finally add the path manually in python3 :
import sys
sys.path.append('/usr/local/lib/python2.7/site-packages')
I get this error :
Traceback (most recent call last): File "<stdin>", line 1, in <module>
File "/usr/local/lib/python2.7/site-packages/mapnik/__init__.py", line 69, in <module>
from _mapnik import * ImportError: dlopen(./_mapnik.so, 2): Symbol not found: _PyClass_Type Referenced from: ./_mapnik.so
Expected in: flat namespace in ./_mapnik.so
Please help, I have spent so many hours on this ...
Thanks!!!
The Mapnik python bindings depend on boost_python. And both need to use the same python. The problem is likely that homebrew is providing a bottle of boost which includes boost python built against python 2.7 and not python 3.x.