I am using ubuntu, linux kernel 2.6.38. I usually use python2, today, I decide to try Python3. I downloads python3 and make install it following the README. However,the python 3.2 interpreter can not recognize UP/SOWN/LEFT/RIGHT keys, these keys are available in my python 2.7 interpreter. What's wrong did I make?
Another question is can I choose the python version which iPython use if I have python2.7 and python3.2 at the same time.
Best Regards.
This happens if the GNU Readline Library is not installed. Install the development version of the Readline library and recompile. (Some Linux distros have different packages for the development version and the runtime version of a library. The development version is needed to compile packages which use the library.)
On Debian-derived distros like Ubuntu, the package is libreadline-dev.
sudo apt install libreadline-dev
On Redhat-derived distros like Fedora, the package is named readline-devel.
sudo dnf install readline-devel
You may be able to use the Editline library instead of Readline. It’s basically a different library that does the same thing.
This happens when compiling python without readline support.
Install the readline developement pakckages so that the readline.so module gets build when compiling.
If you want to use ipython on both python2 and python3, you'll have to install it separately for each interpreter.
One last hint: the ubuntu already has python3 in it's repository. you can install it using:
sudo apt-get install python3 ipython3
Related
You can specify the Python version with a flag (pip install --python-version 3.6 ...), but you can't seem to specify whether you want to install a module that is 32-bit or 64-bit. I have some theories, but its behavior is unclear to me on this point.
To be more specific, I want to use PIP.exe to install a module in an embedded Python area (which does not have its own PIP.exe) using the -t flag to specify the location.
Update: What seems to be the case is that a 32-bit Pip installs to 32-bit Pythons, and a 64-bit Pip installs for 64-bit Pythons.
You can specify the Python version with a flag,
You cannot. Option -t for pip install sets the target directory, not Python version.
but you can't seem to specify whether you want to install a module that is 32-bit or 64-bit.
pip is a Python script, it runs under a Python interpreter and the interpreter certainly knows if it's 32- or 64-bit.
To be more specific, I want to use PIP.exe to install a module in an embedded Python area
You can download packages for a different (from the current Python/pip) hardware platform, OS and Python version but you cannot install them. To install packages you must have a compatible pip. So first thing is to install pip for said embedded Python.
If you're doing something like trying to pull a package off of PyPI using a local pip and dump them into a folder on something like a CircuitPython device, you could try the following:
pip install \
--no-compile \
--target /your/path \
--python-version=3.5 \
--implementation=py \
--no-binary=:all: \
--no-deps \
adafruit-circuitpython-bmp280
That will dump the sources (modules or packages) into /your/path. The --python-version only uses the tags in the package and doesn't actually check the sources. --implementation=py will force it to use pure-python packages
Older answer, but useful for some context
You can specify the Python version with a flag.
Can you clarify this? Are you talking about running something like python3.5 or python3.8? That's the name of the Python binary.
You may also be using Windows, where you can include -32 or -64 as a suffix to the executable in the shebang line. The line is processed by the py PEP-397 launcher.
To eliminate confusion, the best practice is to not run pip install ... but instead python -m pip install .... You're then assured that the pip and python are for the same installation (version, virtual environment, etc.)
For example, if I have Python 2.7, Python 3.5, and Python 3.8 installed, I might have the following 'unambiguous' binaries on my path
python2
python2.7
python3.5
python3.8
However, there's also
python
python3
pip
pip3
What those actually point is anyone's guess and could depend on the install order, how they were installed, and any manual path manipulations. In some setups, pip might install to (e.g.) the Python 3.5 version while python is Python 2.7. If that were the case, if you ran pip install requests then python -c "import requests" it would fail.
To tie it back to the launcher if you're on Windows, running py -3.7-32 myscript.py would run your script with the 32-bit version of Python 3.7, if it exists. If you needed to install a package for it, use py -3.7-32 -m pip install ... to ensure it is installed for it, rather than pip install ... which will go who-knows-where.
I am new to Python. I am running Ubuntu 14.04, and I have both Python 2.7 and 3.4 on it.
I want to use the newer 3.x version, with the NumPy, SciPy, and NLTK libraries. I set the Python REPL path to Python 3.x in the ~/.bash_aliases file like so:
alias python=python3
After this I installed several libs, including python-numpy, python-scipy, and python-matplotlib.
$ sudo apt-get install python-numpy python-scipy python-matplotlib ipython ipython-notebook python-pandas python-sympy python-nose
Unfortunately, I am facing issues since I am guessing that the libraries got installed for the older 2.7 version of Python; I am unable to access the libraries using the 3.4 REPL.
import numpy
ImportError: No module named 'numpy'
However, I am able to access the libraries using the older version:
$ /usr/bin/python2.7
How do I get this this work?
When you install Python packages using apt-get, you're relying on the distribution package manager. The Ubuntu convention is to prefix Python 2 packages with python-, and Python 3 packages with python3-.
This distinction is necessary because Python 3 introduced some incompatible changes from Python 2. It's thus not possible to simply recompile (most) packages for Python 3, meaning both need to be made available.
Alternatively, you can use the Python package manager, pip (or pip3). The catch with this is that some packages (like scipy) require certain compiler toolchains which you might not have installed.
It's generally a good idea to stick to either apt-get or pip for a particular machine. You probably won't have issues if you mix them, but it's better to be consistent.
Being new to Python, I'd love to clear up a few points that I couldn't get from reading various articles and tutorials.
After using Homebrew to install Python3, I noticed that it had installed both Python3 and Python3.4. I was also a little surprised that there are now three versions of pip on my machine too; pip, pip3 and pip3.4.
I created a new virtualenv and told it to use Python3, using the following command:
virtualenv -p /usr/local/bin/python3 mysite
I was also surprised that the version of Python that it installed in my VM was 3.4.
Is it safe to have these multiple version of Python and Pip hanging around on my machine?
Am I right to assume that I should take extra care to use the matching version of pip with Python, for example, pip3.4 with Python3.4?
Yes, it is safe. Python uses this naming like python3.4, python3.5 etc to differentiate between releases. python3 is a symbolic link to the current python3.x version. Pip follows the same convention.
If you're using python3.4 explicitly, you should be using pip3.4 specifically as well. Otherwise, just use python3 and pip3. For Python 2, you can simply use python (which, unless you installed the Homebrew version as well), will be the system Python), and ditto for pip. python2.7 and pip2.7 may also work.
In general, to find out which Python version goes with which pip you're using, try:
pip --version
and you'll see the Python included in the result.
No need to worried about if you have multiple version of Python and Pip installed. just check your version by writing in terminal :
$ brew info python
or to check the version of pip write in terminal :
$ brew info pip
and make sure you have updated your both pip and python version (write in terminal $ brew upgrade pip/python)
and other way to install python is go to https://www.python.org/downloads/ and choose as your requirement, there is two version available 2.7.9 & 3.4.3 ,
after installing python write in terminal $ python -V to check its version :) Hope it will help :)
I'm running Mint 9 and I can't get Virtualenv to run. Every time I run it I get an ImportError for zlib, while the Software Manager claims both zlib1g-dev and zlib1g are installed.
One interesting thing is that there's no PYTHONPATH environment variable set. Is this typical and could it be the problem why zlib can't be found?
Edit:
I also did confirm that it really wasn't available from a standard Python prompt. How do I ensure libraries are available within Python?
Edit:
Ok I found the problem, I was trying to use Python 2.7 and the default for the distro is 2.6. The zlib libraries seem to only be installed into Python 2.6. How do I get them into 2.7 also?
virtualenv doesn't export a PYTHONPATH, instead VIRTUAL_ENV is exported, then the sys.path thing is handled by site module.
The zlib is in the standard library, and it's configured to be enabled by default, so I guess you didn't have zlib-dev installed.
try:
sudo apt-get install zlib1g-dev
and recompile yr python2.7.
I'm a mac newbie and I tried to update my python version from 2.6 to 2.7. Unsuccessful, I changed my mind and uninstalled the python2.7 I had. I had a previous issue that if I typed something like:
python setup.py install
It would not install the package for python2.6, installing to the removed 2.7 version instead, to make it work I have to put
python2.6 setup.py install
And now when I try to install something with easy_install or pip (by the way, pip I have installed after 2.7 issue) I got the following huge message errors: here and here. I want to know how can I clean up my mess.
Since you were trying to install MySQLdb, how about you give ActivePython a try?
Install ActivePython 2.7 (it co-exists with Apple's System Python 2.6)
Open Terminal and type pypm install mysql-python (see PyPM Index) .. no compilation required
Make sure that /usr/local/bin/ is in front of your $PATH.
To uninstall ActivePython, you can do:
sudo /Library/Frameworks/Python.framework/Versions/2.7/Resources/Scripts/uninstall
Or, use sudo pythonselect 2.6 to switch the default Python in /usr/local/bin (if you have multiple versions of non-System Pythons installed)