EzDevInfo.com

python3 interview questions

Top python3 frequently asked interview questions

How do I install Python 3.3?

I have downloaded Python 3.3 from the official site but no idea how to install it.

I'm using Ubuntu 12.04


Source: (StackOverflow)

Install and run Python 3 at the same time than Python 2

Im using 13.04 but I want have installed the both main Python versions for make tests about migration of my actual code.

is possible install Python 3 in the same machine running Python 2.7? I need work with both versions,thanks!


Source: (StackOverflow)

Advertisements

How can I install Django for Python 3.x?

I installed Django with this command:

sudo apt-get install python-django

And it installed version 1.5.4-1ubuntu1. The Django docs say that as of version 1.5, Django supports Python 3. Yet when I run the python 3 interpreter and try importing Django, it says there's no such module. I tried looking for a python3 version of Django, but no such package exists. How can I get django working on python3? I'd prefer to use ubuntu packages instead of installing things manually.


Source: (StackOverflow)

Make default python symbolic link to link to python3

I can access Python 3 via python3 command. But I want to make the default interpreter to use python command for Python 3. Simple typing python takes me to Python 2. How to change this?


Source: (StackOverflow)

How to install Python 3.4 on Ubuntu?

If I open Terminal and type in python, I see the version is 2.7.4. How do I get python 3.4? And do I need IDLE if I have sublime text?


Source: (StackOverflow)

How to install pip for python 3 in ubuntu 12.04 LTS

I am trying to install the Pillow module for python 3.3, but for that I need to install pip. Every time that I install pip it installs for python 2.7, any help?


Source: (StackOverflow)

pyvenv-3.4 error: returned non-zero exit status 1

When trying to create a virtual environment using the included pyvenv-3.4 that comes with 14.04, it throws an error:

Error: Command '['/some/directories/bin/python3.4', '-Im', 'ensurepip', '--upgrade', '--default-pip']' returned non-zero exit status 1

How do I use pyvenv-3.4 with Ubuntu 14.04?


Source: (StackOverflow)

How to create a virtualenv with Python3.3 in Ubuntu?

I'm running Precise Pangolin amd64. I installed Python 3.3 from ppa:fkrull/deadsnakes.

Now I want to actually use this new Python version in a virtualenv. But How can I do this? I get the following error:

$ virtualenv --no-site-packages --distribute -p /usr/bin/python3.3 ~/.virtualenvs/pywork3
Running virtualenv with interpreter /usr/bin/python3.3
The --no-site-packages flag is deprecated; it is now the default behavior.
New python executable in /home2/USERNAME/.virtualenvs/pywork3/bin/python3.3
Also creating executable in /home2/USERNAME/.virtualenvs/pywork3/bin/python
Traceback (most recent call last):
  File "/usr/local/lib/python2.7/site-packages/site.py", line 73, in <module>
    __boot()
  File "/usr/local/lib/python2.7/site-packages/site.py", line 2, in __boot
    import sys, imp, os, os.path   
ImportError: No module named 'imp'
ERROR: The executable /home2/USERNAME/.virtualenvs/pywork3/bin/python3.3 is not functioning
ERROR: It thinks sys.prefix is '/home2/USERNAME/.virtualenvs' (should be '/home2/USERNAME/.virtualenvs/pywork3')
ERROR: virtualenv is not compatible with this system or executable

If instead, I explicitly use python3.3 to call virtualenv, I get this error:

$ python3.3 /usr/bin/virtualenv --no-site-packages --distribute -p /usr/bin/python3.3 ~/.virtualenvs/pywork3
Traceback (most recent call last):
  File "/usr/bin/virtualenv", line 2, in <module>
    import virtualenv
ImportError: No module named 'virtualenv'

I'm stuck. Any help is greatly appreciated!

EDIT: Following the advise by @thefourtheye, I purged my local site-packages directory (effectively only deleting site.py). Now I'm getting a step further, but virtualenv complains about a missing easy_install:

 Error [Errno 2] No such file or directory:   
'/home2/USERNAME/.virtualenvs/pywork3/bin/easy_install' while executing command    
/home2/USERNAME/.virt...rk3/bin/easy_install /usr/share/python-virtualenv/pip-1.1.tar.gz

I did install the package python3-setuptools, which installs the Py3 version of easy_install.

EDIT2:

Here's the verbose output, without explicitly passing --distribute and --no-site-packages, as these two switches are default behaviour of my virtualenv:

$ virtualenv --verbose -p /usr/bin/python3.3 ~/.virtualenvs/pywork3
Running virtualenv with interpreter /usr/bin/python3.3
Creating /home2/USERNAME/.virtualenvs/pywork3/lib/python3.3
Symlinking Python bootstrap modules
  Symlinking /home2/USERNAME/.virtualenvs/pywork3/lib/python3.3/config-3.3m
  Symlinking /home2/USERNAME/.virtualenvs/pywork3/lib/python3.3/lib-dynload
  Symlinking /home2/USERNAME/.virtualenvs/pywork3/lib/python3.3/os.py
  Ignoring built-in bootstrap module: posix
  Symlinking /home2/USERNAME/.virtualenvs/pywork3/lib/python3.3/posixpath.py
  Cannot import bootstrap module: nt
  Symlinking /home2/USERNAME/.virtualenvs/pywork3/lib/python3.3/ntpath.py
  Symlinking /home2/USERNAME/.virtualenvs/pywork3/lib/python3.3/genericpath.py
  Symlinking /home2/USERNAME/.virtualenvs/pywork3/lib/python3.3/fnmatch.py
  Symlinking /home2/USERNAME/.virtualenvs/pywork3/lib/python3.3/locale.py
  Symlinking /home2/USERNAME/.virtualenvs/pywork3/lib/python3.3/encodings
  Symlinking /home2/USERNAME/.virtualenvs/pywork3/lib/python3.3/codecs.py
  Symlinking /home2/USERNAME/.virtualenvs/pywork3/lib/python3.3/stat.py
  Cannot import bootstrap module: UserDict
  Cannot import bootstrap module: copy_reg
  Symlinking /home2/USERNAME/.virtualenvs/pywork3/lib/python3.3/types.py
  Symlinking /home2/USERNAME/.virtualenvs/pywork3/lib/python3.3/re.py
  Cannot import bootstrap module: sre
  Symlinking /home2/USERNAME/.virtualenvs/pywork3/lib/python3.3/sre_parse.py
  Symlinking /home2/USERNAME/.virtualenvs/pywork3/lib/python3.3/sre_constants.py
  Symlinking /home2/USERNAME/.virtualenvs/pywork3/lib/python3.3/sre_compile.py
  Ignoring built-in bootstrap module: zlib
  Cannot import bootstrap module: _abcoll
  Symlinking /home2/USERNAME/.virtualenvs/pywork3/lib/python3.3/warnings.py
  Symlinking /home2/USERNAME/.virtualenvs/pywork3/lib/python3.3/linecache.py
  Symlinking /home2/USERNAME/.virtualenvs/pywork3/lib/python3.3/abc.py
  Symlinking /home2/USERNAME/.virtualenvs/pywork3/lib/python3.3/io.py
  Symlinking /home2/USERNAME/.virtualenvs/pywork3/lib/python3.3/_weakrefset.py
  Symlinking /home2/USERNAME/.virtualenvs/pywork3/lib/python3.3/copyreg.py
  Symlinking /home2/USERNAME/.virtualenvs/pywork3/lib/python3.3/tempfile.py
  Symlinking /home2/USERNAME/.virtualenvs/pywork3/lib/python3.3/random.py
  Symlinking /home2/USERNAME/.virtualenvs/pywork3/lib/python3.3/__future__.py
  Symlinking /home2/USERNAME/.virtualenvs/pywork3/lib/python3.3/collections
  Symlinking /home2/USERNAME/.virtualenvs/pywork3/lib/python3.3/keyword.py
  Symlinking /home2/USERNAME/.virtualenvs/pywork3/lib/python3.3/tarfile.py
  Symlinking /home2/USERNAME/.virtualenvs/pywork3/lib/python3.3/shutil.py
  Symlinking /home2/USERNAME/.virtualenvs/pywork3/lib/python3.3/struct.py
  Symlinking /home2/USERNAME/.virtualenvs/pywork3/lib/python3.3/copy.py
  Symlinking /home2/USERNAME/.virtualenvs/pywork3/lib/python3.3/base64.py
  Symlinking /home2/USERNAME/.virtualenvs/pywork3/lib/python3.3/bisect.py
  Symlinking /home2/USERNAME/.virtualenvs/pywork3/lib/python3.3/_dummy_thread.py
  Symlinking /home2/USERNAME/.virtualenvs/pywork3/lib/python3.3/hashlib.py
  Symlinking /home2/USERNAME/.virtualenvs/pywork3/lib/python3.3/heapq.py
  Symlinking /home2/USERNAME/.virtualenvs/pywork3/lib/python3.3/hmac.py
  Symlinking /home2/USERNAME/.virtualenvs/pywork3/lib/python3.3/reprlib.py
  Symlinking /home2/USERNAME/.virtualenvs/pywork3/lib/python3.3/rlcompleter.py
  Symlinking /home2/USERNAME/.virtualenvs/pywork3/lib/python3.3/weakref.py
Creating /home2/USERNAME/.virtualenvs/pywork3/lib/python3.3/site-packages
Writing /home2/USERNAME/.virtualenvs/pywork3/lib/python3.3/site.py
Writing /home2/USERNAME/.virtualenvs/pywork3/lib/python3.3/orig-prefix.txt
Writing /home2/USERNAME/.virtualenvs/pywork3/lib/python3.3/no-global-site-packages.txt
Creating parent directories for /home2/USERNAME/.virtualenvs/pywork3/include
Symlinking /home2/USERNAME/.virtualenvs/pywork3/include/python3.3m
Creating /home2/USERNAME/.virtualenvs/pywork3/bin
New python executable in /home2/USERNAME/.virtualenvs/pywork3/bin/python3.3
Changed mode of /home2/USERNAME/.virtualenvs/pywork3/bin/python3.3 to 0o755
Also creating executable in /home2/USERNAME/.virtualenvs/pywork3/bin/python
Changed mode of /home2/USERNAME/.virtualenvs/pywork3/bin/python to 0o755
Testing executable with /home2/USERNAME/.virtualenvs/pywork3/bin/python3.3 -c "
import sys
prefix = sys.prefix
if sys.version_info[0] == 3:
    prefix = prefix.encode('utf8')
if hasattr(sys.stdout, 'detach'):
    sys.stdout = sys.stdout.detach()
elif hasattr(sys.stdout, 'buffer'):
    sys.stdout = sys.stdout.buffer
sys.stdout.write(prefix)
"
Got sys.prefix result: '/home2/USERNAME/.virtualenvs/pywork3'
Creating /home2/USERNAME/.virtualenvs/pywork3/lib/python3.3/distutils
Writing /home2/USERNAME/.virtualenvs/pywork3/lib/python3.3/distutils/__init__.py
Writing /home2/USERNAME/.virtualenvs/pywork3/lib/python3.3/distutils/distutils.cfg
Using existing distribute egg: /usr/share/python-virtualenv/distribute-0.6.24.tar.gz
Installing distribute..............................................................................................................................................................................................................................................................................................................................................................................................................done.
Installing existing pip-1.1.tar.gz distribution: /usr/share/python-virtualenv/pip-1.1.tar.gz
Installing pip...
  Error [Errno 2] No such file or directory: '/home2/USERNAME/.virtualenvs/pywork3/bin/easy_install' while executing command /home2/USERNAME/.virt...rk3/bin/easy_install /usr/share/python-virtualenv/pip-1.1.tar.gz
...Installing pip...done.
Traceback (most recent call last):
  File "/usr/lib/python2.7/dist-packages/virtualenv.py", line 2283, in <module>
    main()
  File "/usr/lib/python2.7/dist-packages/virtualenv.py", line 938, in main
    never_download=options.never_download)
  File "/usr/lib/python2.7/dist-packages/virtualenv.py", line 1054, in create_environment
    install_pip(py_executable, search_dirs=search_dirs, never_download=never_download)
  File "/usr/lib/python2.7/dist-packages/virtualenv.py", line 643, in install_pip
    filter_stdout=_filter_setup)
  File "/usr/lib/python2.7/dist-packages/virtualenv.py", line 976, in call_subprocess
    cwd=cwd, env=env)
  File "/usr/lib/python3.3/subprocess.py", line 818, in __init__
    restore_signals, start_new_session)
  File "/usr/lib/python3.3/subprocess.py", line 1416, in _execute_child
    raise child_exception_type(errno_num, err_msg)
FileNotFoundError: [Errno 2] No such file or directory: '/home2/USERNAME/.virtualenvs/pywork3/bin/easy_install'

Source: (StackOverflow)

What is python3mu?

I'm setting up PyDev for Eclipse, and I have to choose a version of Python for the interpretor. I want to use Python3, and I've been using python3 as my interpretor, so I thought /usr/bin/python3 would have been the obvious choice. However, another option there is python3mu. I ran this in the terminal and it seemed to function exactly like python3. My questions are: Which one is the correct one to use as the interpretor for Eclipse? and What is the difference between the two?

EDIT: Just wanted to let you guys know that my google-fu was not good enough to find out what python3mu was.


Source: (StackOverflow)

Why isn't python 3 the default python binary?

I type python in a terminal window. I get Python 2.7 and not Python 3.5. According to the docs, Python 3.5 should come preloaded.


Source: (StackOverflow)

pyvenv-3.4 disappeared in Ubuntu 14.04.3?

This is what I was doing to create a venv in Python 3.4 on Ubuntu 14.04.3 LTS until last week:

» pyvenv-3.4 --without-pip venv

I was doing that because of this. But since yesterday:

» pyvenv-3.4 --without-pip venv
The program 'pyvenv-3.4' is currently not installed. You can install it by typing:
sudo apt-get install python3.4

python3.4 is definitely installed:

» python3.4 --version
Python 3.4.3

I have probably done an apt-upgrade recently, but ... why has pyvenv-3.4 disappeared?


Source: (StackOverflow)

'unsupported locale setting' fault by command-not-found

I recently installed Ubuntu 12.10 by keeping the home folders from Linux Mint 13 distribution. The system installed fine, but at the beginning everything was in Chinese (even the text in the Terminal). I managed to solve that by editing some files, but I still get an error whenever a command is not found in Terminal. Here it is:

Sorry, command-not-found has crashed! Please file a bug report at:
https://bugs.launchpad.net/command-not-found/+filebug
Please include the following information with the report:

command-not-found version: 0.3
Python version: 3.2.3 final 0
Distributor ID: Ubuntu
Description:    Ubuntu 12.10
Release:    12.10
Codename:   quantal
Exception information:

unsupported locale setting
Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/CommandNotFound/util.py", line 24, in crash_guard
callback()
  File "/usr/lib/command-not-found", line 69, in main
enable_i18n()
  File "/usr/lib/command-not-found", line 40, in enable_i18n
locale.setlocale(locale.LC_ALL, '')
  File "/usr/lib/python3.2/locale.py", line 541, in setlocale
return _setlocale(category, locale)
locale.Error: unsupported locale setting

How can I get rid of this error. It says that it is a locale error, so I guess it might be related to the initial language problem, but I'm not an expert in linux stuff. What is your opinion?


Source: (StackOverflow)

Installation procedure for numpy and other python-3.4 packages on ubuntu 14.04

I am new to ubuntu and installed ubuntu 14.04 32 bit on my LENOVO hinkpad T410 machine with windows 7 two days ago but since then trying download and install python-3.4 packages (NUMPY, SCIPY) on ubuntu and not getting results. I have Downloaded IDLE through ubuntu software centre but numpy neither run for me from ubuntu software centre nor from commands.

    sudo apt-get install python-numpy

it gives me:

    E: Unable to locate package python-numpy_1.8.1-1ubuntu1_i386
    E: Couldn't find any package by regex 'python-numpy_1.8.1-1ubuntu1_i386'

I also tried:

    pip install python-numpy

but it results:

    Could not find any downloads that satisfy the requirement python-numpy
    Cleaning up...
    No distributions at all found for python-numpy
    Storing debug log for failure in /home/sibte/.pip/pip.log

Any guide for the very beginners to ubuntu.


Source: (StackOverflow)

How to download pygame in python3.3

I am using Ubuntu 13.10.I have both python 2.7 and python 3.3.I have installed pygame properly in python 2.7.How can i install it in python3.3.Does pygame support python3.3 or not?


Source: (StackOverflow)

How to find python installation directory on ubuntu

I have just migrated from Windows environment. I have installed Python 3.2 in a separate directory. How can I get the python installation path on ubuntu shell ?

Is there any way I can let shell know/choose at runtime which python version is to be used for further code execution ?

Are there any kind of environment variables and search path kind of thing in ubuntu linux as well ?


Source: (StackOverflow)