How to completely replace python 3 with python 2 in arch linux - python-2.7

I want to completely replace python 3 with python 2 in arch linux. I have already read https://wiki.archlinux.org/index.php/Python but it only provides a temporary fix. I need to ensure that when I call
#!/usr/bin/python
My program is using python 2 instead of python 3.

In Arch, /usr/bin/python is actually a symlink to python3. Assuming you've already installed python2, as root, change the symlink to point to python2:
cd /usr/bin
ls -l python
lrwxrwxrwx 1 root root 7 5 sept. 07:04 python -> python3
ln -sf python2 python
ls -l python
lrwxrwxrwx 1 root root 7 Dec 11 19:28 python -> python2
If you're using the python2-virtualenv package, then do the same for /usr/bin/virtualenv:
cd /usr/bin
ln -sf virtualenv2 virtualenv

Changing the default symlink is a bad idea, and it gets recreated on python3 updates. Instead, create a local python override:
sudoedit /usr/local/bin/python
Paste this inside and save the file:
#!/bin/bash
exec python2 "$#"
Don't forget to make it executable:
sudo chmod +x /usr/local/bin/python

Related

How to create virtual environment in pythonware?

8:59 ~ $ mkvirtualenv --python=3.7 myproj`
The path 3.7 (from --python=3.7) does not exist
also tried with 3.5 and the path of python.exe its not working
make sure that the python version is equals to the python version in your device and it should work. and for the command do it this way~ mkvirtualenv myproj --python=/user/bin/python3.7 (this is the location of the python where its located)

kaldi python2 binary issue

I am installing kaldi in ubuntu 18.04. python2.7 is one of the dependencies to install kaldi. I have installed python2.7 by sudo apt-get install pytho2.7. Then to check the prerequisites run
extras/check_dependencies.sh. The result showing - "python2.7 is installed, but the python2 binary does not exit. Creating a symlink and adding this to tools/env.sh"
What is the next step to do?
You should add symlink to python2.7 binary:
ln -fs /usr/bin/python2.7 $(KALDI_ROOT)/tools/python/python2
Where $(KALDI_ROOT) is a root directory of Kaldi source code
i just input 'ln -fs /usr/bin/python2.7'

libexpat could not be found by linux system

I am developing with vddk library for ubuntu 12.10 i386. I constantly get following error:
Cannot open library: libexpat.so.0: cannot open shared object file: No such file or directory.
When I run apt-file search libexpat.so
it shows me following
lib64expat1: /usr/lib64/libexpat.so.1
lib64expat1: /usr/lib64/libexpat.so.1.6.0
lib64expat1-dev: /usr/lib64/libexpat.so
libexpat1: /lib/i386-linux-gnu/libexpat.so.1
libexpat1: /lib/i386-linux-gnu/libexpat.so.1.6.0
libexpat1-dev: /usr/lib/i386-linux-gnu/libexpat.so
I already tried to create a symlink
sudo ln -s /usr/lib/i386-linux-gnu/libexpat.so /usr/lib/i386-linux-gnu/libexpat.so.0
but it did not work.
Strange thing:
ls -l `locate libexpat.so`
ls: cannot access /lib/i386-linux-gnu/libexpat.so.1: No such file or directory
ls: cannot access /lib/i386-linux-gnu/libexpat.so.1.6.0: No such file or directory
ls: cannot access /usr/lib/vmware-vix-disklib/lib64/libexpat.so.0: No such file or directory
-rw-r--r-- 1 ubuntu ubuntu 141320 Aug 20 09:21 /home/ubuntu/vddk/lib64/libexpat.so.0
-rw-r--r-- 1 root root 141320 Feb 3 16:45 /usr/lib/vmware-vix-disk-lib/vmware-vix-disk-lib/lib64/libexpat.so.0
-rw-r--r-- 1 root root 141320 Aug 20 09:21 /usr/vmware-vix-disklib-distrib/lib64/libexpat.so.0
apt-file shows only the contents of a package, or in your case the package(s) by file name, but it works regardless of whether the package is installed or not.
You need to install libexpat1:
sudo apt-get install libexpat1
If you are about to compile and link custom C programs against libexpat1 you will also need:
sudo apt-get install libexpat1-dev
Fixed by
manually downloading and installing libexpat package form here
http://expat.sourceforge.net/ and look for downloading page. It should take you to sourceforge page and select stable package
Go to the source code download page and build with the correct flag.
Since you are building for x86, you'll need to run configure like this:
./configure CFLAGS=-m32

Management command not found without unzipping .egg

I have a django app that I've packaged according to the docs here: https://docs.djangoproject.com/en/1.5/intro/reusable-apps/
I installed the app into a virtual environment using setup.py.
./setup.py install
The app's web UI runs fine from the virtual environment. But I cannot access the custom management command with this vanilla install.
(django_grm)[grm#controller django_grm]$ python ./manage.py sync_to_graphite
Unknown command: 'sync_to_graphite'
Here's what the virtual environment looks like when the command will not execute:
(django_grm)[grm#controller django_grm]$ ll /home/grm/venv/django_grm/lib/python2.7/site-packages
total 1148
...
-rw-rw-r-- 1 grm grm 243962 Jun 19 17:11 django_grm-0.0.4-py2.7.egg
...
However, once I unzip the .egg file, the management command works as expected.
(django_grm)[grm#controller django_grm]$ cd /home/grm/venv/django_grm/lib/python2.7/site-packages
(django_grm)[grm#controller site-packages]$ unzip django_grm-0.0.4-py2.7.egg
(django_grm)[grm#controller site-packages]$ ll /home/grm/venv/django_grm/lib/python2.7/site-packages
total 1152
...
-rw-rw-r-- 1 grm grm 243962 Jun 19 17:11 django_grm-0.0.4-py2.7.egg
drwxrwxr-x 6 grm grm 4096 Jun 19 17:16 dj_grm
...
(django_grm)[grm#controller site-packages]$ cd /home/grm/django_projects/django_grm/
(django_grm)[grm#controller django_grm]$ python ./manage.py sync_to_graphite
<success>
Is this normal behaviour? It feels wonky.
I strongly suggest using pip instead of setup.py. It tends to do a much better job of installing packages as well as managing them.
Once you have your virtual environment in place, it would be:
$ . env/bin/activate
$ pip install [APP_NAME]
This installs a non-zipped version of the app in the virtual environment.
If the app is a zip from somewhere, you can still use pip
$ pip install http://[URL_TO_ZIP]
Let's take a look at the part of the source that loads management commands:
def find_commands(management_dir):
"""
Given a path to a management directory, returns a list of all the command
names that are available.
Returns an empty list if no commands are defined.
"""
command_dir = os.path.join(management_dir, 'commands')
try:
return [f[:-3] for f in os.listdir(command_dir)
if not f.startswith('_') and f.endswith('.py')]
except OSError:
return []
which is called by:
# Find and load the management module for each installed app.
for app_name in apps:
try:
path = find_management_module(app_name)
_commands.update(dict([(name, app_name)
for name in find_commands(path)]))
except ImportError:
pass # No management module - ignore this app
So, yeah, Django doesn't support apps installed in a zipped file, at least here; it wants an explicit commands directory inside management_dir.
As #tghw notes, installing via pip will keep the package in a directory instead of zipping it. You can also (and probably should also) set zip_safe=False in your setup() command; this will stop setuptools/distribute/etc from trying to zip up your package no matter how you install it.

How to do wapiti security test step by step procedure in windows 7 (Its show no error)

Installed python 2.7
D:\wapiti\wapiti-2.2.1\src> python wapiti.py <server url>/ -s
i didnt get any errors. i got one html file with no error
D:\wapiti\wapiti-2.2.1\src> python wapiti.py http://serverdomain/Dashboard/Index/ -u
D:\wapiti\wapiti-2.2.1\net> python getcookie.py http://serverdomain/Dashboard/Index/ -c <file url>
D:\wapiti\wapiti-2.2.1\src> python wapiti.py http://serverdomain/Dashboard/Index/ -a username%password
1.You download the zip (wapiti-2.3.0-win32-standalone) package,extract it and change directory into it (e.g. cd wapiti-2.0.X)
2.Install the Python 2.6 or 2.7 on window machine.
Execute the below command using cmd :-
#wapiti-getcookie cookies.json http://stage.xxxxxxx.com/login
#wapiti http://stage.xxxxxxxx.com -c cookies.json -x http://stage.xxxxxxx.com/logout