Python3 always shows ImportError message
<p>Whenever I try to run a script the python interpreter always shows an <code>ImportError</code> message such as (e.g.) <code>No module named 'setuptools'</code>. So, I tried install (or to satisfy this requirement) with <code>apt-get</code>... I do this for both Python 2.7 and Python 3.5 until <code>Requirement already satisfied</code>.</p>

<p>First of all, I don't work with Python 2.7, but it's the defaul version for the interpreter. So, how could I solve this problem to work with Python 3.5? I tried this:</p>

<pre><code>&gt;&gt;&gt; import sys
&gt;&gt;&gt; print(sys.path)
['',
 '/usr/local/lib/python35.zip',
 '/usr/local/lib/python3.5',
 '/usr/local/lib/python3.5/plat-linux',
 '/usr/local/lib/python3.5/lib-dynload',
 '/usr/local/lib/python3.5/site-packages']
</code></pre>

<p>This was for <strong>Python3</strong>, for Python2 I did the same to compare the paths and I got this:</p>

<pre><code>&gt;&gt;&gt; import sys
&gt;&gt;&gt; print(sys.path)
['',
 '/usr/local/lib/python2.7/dist-packages/pygame-1.9.2b8-py2.7-linux-x86_64.egg',
 '/usr/lib/python2.7',
 '/usr/lib/python2.7/plat-x86_64-linux-gnu',
 '/usr/lib/python2.7/lib-tk',
 '/usr/lib/python2.7/lib-old',
 '/usr/lib/python2.7/lib-dynload',
 '/usr/local/lib/python2.7/dist-packages',
 '/usr/lib/python2.7/dist-packages',
 '/usr/lib/python2.7/dist-packages/PILcompat',
 '/usr/lib/python2.7/dist-packages/gtk-2.0']
</code></pre>

<p>Now... Should it work if I use the <code>append()</code> method to add all the paths of Python2 to the paths in Python3? Also, I've been considered to completely uninstall Python2, but I know this will cause more problems in my system that the one I try to solve.</p>

<p>From your description of the problem, you have likely been installing the Python 2 versions of the packages you want with <code>apt</code> and/or <code>pip</code>. <code>sudo apt-get install python-django</code>, for example, will install the Python 2 version of Django, while <code>sudo apt-get install python3-django</code> installs the Py3 version. </p>

<p>You will eventually run into a situation where you need to use <code>pip</code>, as a package you want won't be in the Debian/Ubuntu repositories. In that case, make sure you're using the right <code>pip</code>. Try running</p>

<pre><code>pip -V
</code></pre>

<p>and</p>

<pre><code>pip3 -V
</code></pre>

<p>to see which Python versions are attached when you call <code>pip</code>, then use the appropriate one for the version of Python you wish to target.</p>

<p>Finally, <em>under no circumstances whatsoever</em> should you add the Python 2 paths to Python 3's <code>sys.path</code>.</p>

<hr>

<h2>EDIT</h2>

<p>Here is my <code>sys.path</code> on Ubuntu 16.04 using the system's Python 3.5.2:</p>

<pre><code>$ python3
Python 3.5.2 (default, Jul  5 2016, 12:43:10) 
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.
&gt;&gt;&gt; import sys
&gt;&gt;&gt; from pprint import pprint as pp
&gt;&gt;&gt; pp(sys.path)
['',
 '/usr/local/lib/python3.5/dist-packages/pandas-0.18.1-py3.5-linux-x86_64.egg',
 '/usr/local/lib/python3.5/dist-packages/github3.py-1.0.0a4-py3.5.egg',
 '/usr/local/lib/python3.5/dist-packages/uritemplate.py-0.3.0-py3.5.egg',
 '/usr/lib/python3/dist-packages',
 '/usr/lib/python35.zip',
 '/usr/lib/python3.5',
 '/usr/lib/python3.5/plat-x86_64-linux-gnu',
 '/usr/lib/python3.5/lib-dynload',
 '/usr/local/lib/python3.5/dist-packages']
&gt;&gt;&gt; print(sys.executable)
/usr/bin/python3
&gt;&gt;&gt;
</code></pre>

<p>You'll notice that the paths are <code>dist-packages</code> paths, while you have <code>site-packages</code>. From a user's perspective, there's very little difference between the two, so don't worry about it. I also changed some of my paths on purpose (it's a long story).</p>

python python-2.7 python-3.x pip importerror