Hot answers tagged

82

From the comment: sudo update-alternatives --config python Will show you an error: update-alternatives: error: no alternatives for python3 You need to update your update-alternatives , then you will be able to set your default python version. sudo update-alternatives --install /usr/bin/python python /usr/bin/python3.4 1 sudo update-alternatives --...


80

Ubuntu 16.10+ and Python 3.7 dev sudo apt-get install zlib1g-dev note: i only put this here because it was the top search result for the error, but this resolved my issue. update: also the case for ubuntu 14.04LTS and base kernel at 4.1+


54

Shell loops are slow and bash's are the slowest. Shells aren't meant to do heavy work in loops. Shells are meant to launch a few external, optimized processes on batches of data. Anyway, I was curious how shell loops compare so I made a little benchmark: #!/bin/bash export IT=$((10**6)) echo POSIX: for sh in dash bash ksh zsh; do TIMEFORMAT="%RR %UU %...


23

The solution is : # yum install zlib-devel


18

I did a bit of testing, and on my system ran the following--none made the order of magnitude speedup that would be needed to be competitive, but you can make it faster: Test 1: 18.233s #!/bin/bash i=0 while [[ $i -le 4000000 ]] do let i++ done test2: 20.45s #!/bin/bash i=0 while [[ $i -le 4000000 ]] do i=$(($i+1)) done test3: 17.64s #!/bin/...


17

This is a known bug in bash; see the man page and search for "BUGS": BUGS It's too big and too slow. ;) For an excellent primer on the conceptual differences between shell scripting and other programming languages, I highly recommend reading: Why is using a shell loop to process text considered bad practice? The most pertinent excerpts: Shells ...


10

A shell is efficient if you use it for what it has been designed for (though efficiency is rarely what you look for in a shell). A shell is a command-line interpreter, it is designed to run commands and have them cooperate to a task. If you want to count to 1000000000, you invoke a (one) command to count, like seq, bc, awk or python/perl... Running ...


8

The issue is that simply executing has('python') in an if-statement causes python3 to be unavailable when vim was compiled with both python/dyn and python3/dyn. The simplest solution is probably just to add something like if exists('py2') && has('python') elseif has('python3') endif to your .vimrc before Vundle loads anything. Then, if you ever ...


8

python36u is an alternative build provided by IUS; python36 is an EPEL package. yum info python36 python36u will show you different repos for the two, and it's likely that the IUS one has a slightly higher minor version number than the EPEL package. And just to make things even more confusing, there's also Redhat Software Collections, which provide rh-...


8

Simple solution is edit .bashrc and put this line: alias python3=python3.7 Whenever you will write python3 it will replace it with python3.7. Or you can use command update-alternatives which is preferred i.e: sudo update-alternatives --install /usr/bin/python python /usr/bin/python3.6 1 sudo update-alternatives --install /usr/bin/python python /usr/bin/...


7

Answer: Bash is much slower than Python. One little example is in blog post Performance of several languages.


7

Create symlink for /usr/bin/python3. In my LinuxMint: # ls -lh /usr/bin/python3 /usr/bin/python lrwxrwxrwx 1 root root 9 ноя 24 2017 /usr/bin/python -> python2.7 lrwxrwxrwx 1 root root 9 сен 6 2017 /usr/bin/python3 -> python3.5 # mv /usr/bin/python # cp /usr/bin/python3 /usr/bin/python # python --version Python 3.5.2


7

You can achieve this by applying below simple steps - Check python version on terminal - python --version Get root user privileges. On terminal type - sudo su Write down the root user password Execute this command to switch to python 3.6 - update-alternatives --install /usr/bin/python python /usr/bin/python3 1 Check python version - python --version Done.


6

This doesn't work because source is a shell command, so systemd's ExecStart= or ExecStartPre= won't understand them directly... (BTW, the same is true for cd and the &&.) You could achieve that by running a shell explicitly and running all your commands together there: ExecStart=/bin/sh -c 'cd /home/debian/ap/ && source venv-ap/bin/activate ...


6

using these commands can help you: check the version of python: ls /usr/bin/python* alias: alias python='/usr/bin/pythonxx' re-login: . ~/.bashrc check the python version again: python --version


6

Apparently the issue was related to the opencv-python library. I tried to open a python session and import that module mannually but it produced the same error. I removed that module from pip and installed it again with apt install python3-opencv. It worked.


5

Unix systems don't really have a “system language”. Unix is a multiuser system and each user is free to pick their preferred language. The closest thing to a system language is the default language that users get if they don't configure their account. The location of that setting varies from distribution to distribution; it's picked up at some point during ...


5

Ubuntu 14.04 has the lsb_release.py file installed for Python 2.7 as well and lsb_release seems to work under python2.7 as well. You can try this by doing: python2.7 /usr/bin/lsb_release If that works, make a backup of the file /usr/bin/lsb_release and change the first line to read: #! /usr/bin/python2.7 (you can experiment with the -Es options, I would ...


5

I was missing libpq-fe.h, which I obtained by installing postgresql-devel sudo yum install postgresql-devel


5

There is a command line option that suits your needs: #!/usr/bin/env python3 -E -E Ignore all PYTHON* environment variables, e.g. PYTHONPATH and PYTHONHOME, that might be set.


5

You do not need to uninstall Python 2 in order to install Python 3. apt-get install python3 will install it in parallel. Also, in Ubuntu, the minimal subset of Python provided by python-minimal is an essential package, so uninstalling it could have catastrophic consequences.


5

I just had to do this, I find whenever I build python from source I have many issues (the 2 most annoying are not having a history when pressing the up key and getting an _sqlite module not available! Both can be fixed but it's just annoying having to fix them). So to answer your question, the best way is to add Felix Krull's deadsnakes PPA at; https://...


4

Just for fun: python -c 'import sys,fileinput,re;sys.stdout.writelines(re.sub("stuff", "changed", l, 1) for l in fileinput.input() if re.search("patternmatch", l))' file Don't do it:) Use sed/perl/awk


4

Your system may not be looking in /usr/local/lib by default for shared libraries. When you compile things, set the environment variable: export LD_RUN_PATH=/usr/local/lib This is only needed when you compile things. That or add /usr/local/lib to the directories searched by the system for shared libraries.


4

It's very likely that the python command has been hashed and that you need to clear the cache. In order to see what executable is actually being run you can use the type command, e.g.: type -a python Unlike the which command, the type command is aware of hashed programs, as well as aliases and shell functions. For further discussion of which (no pun ...


4

By default only Python 2.7 is shipped with CentOS 7, so using pip instead of pip3 only builds from Python 2.7. You'll want to enable EPEL repository, then install Python 3.4 and then get pip3. sudo yum install epel-release sudo yum install python34 python 34-setuptools sudo easy_install-3.4 pip then go back and run pip3 install python-openstackclient ...


4

As is typical with some of the modules in ansible you have to install certain Python modules on the remote server's side. https://github.com/ansible/ansible/issues/21416 You can use the pip module to facilitate this through your ansible playbook like so: - name install pexpect pip: name: pexpect become: yes Your distro may have these available as ...


3

Nothing is wrong (except your expectations) as python is really rather fast for non-compiled language, see https://wiki.python.org/moin/PythonSpeed


3

When setting DEFAULT_VERSIONS=python=3.5 python2=2.7 python3=3.5 in /etc/make.conf you have to rebuild the ports that use the default version of Python.


3

I found this post which mentioned to configure which ATLAS (linear algebra package) version to use: $ sudo update-alternatives --set libblas.so.3 /usr/lib/atlas-base/atlas/libblas.so.3 $ sudo update-alternatives --set liblapack.so.3 /usr/lib/atlas-base/atlas/liblapack.so.3 After that, I was happily surprised that in fact there was no longer a permissions ...


Only top voted, non community-wiki answers of a minimum length are eligible