Python Forum

Full Version: how to check if i have installed python correct?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
hello dear python-experts,

i am apollo - pretty new to python. i have installed python on my opensuse leap 42.3. box:

afterwards i have installed bs4 - see below.
note - i did this as root. Hopefully this is correct.

linux-3645:/home/martin # pip install --upgrade pip                                                                                                                                             
Collecting pip                                                                                                                                                                                  
  Downloading pip-9.0.1-py2.py3-none-any.whl (1.3MB)                                                                                                                                            
    100% |████████████████████████████████| 1.3MB 155kB/s 
Installing collected packages: pip                                                                                                                                                              
  Found existing installation: pip 7.1.2                                                                                                                                                        
    Uninstalling pip-7.1.2:                                                                                                                                                                     
      Successfully uninstalled pip-7.1.2                                                                                                                                                        
Successfully installed pip-9.0.1                                                                                                                                                                
linux-3645:/home/martin # pip install beautifulsoup4
Collecting beautifulsoup4                                                                                                                                                                       
  Downloading beautifulsoup4-4.6.0-py3-none-any.whl (86kB)
    100% |████████████████████████████████| 92kB 394kB/s 
Installing collected packages: beautifulsoup4
Successfully installed beautifulsoup4-4.6.0
linux-3645:/home/martin # 
To test if all went all right i tried the following:
import urllib
from bs4 import BeautifulSoup
import urlparse
import mechanize


# Set the startingpoint for the spider and initialize 
# the a mechanize browser object
url = "http://sparkbrowser.com"
br = mechanize.Browser()

# create lists for the urls in que and visited urls
urls = [url]
visited = [url]


# Since the amount of urls in the list is dynamic
#   we just let the spider go until some last url didn't
#   have new ones on the webpage
while len(urls)>0:
    try:
        br.open(urls[0])
        urls.pop(0)
        for link in br.links():
            newurl =  urlparse.urljoin(link.base_url,link.url)
            #print newurl
            if newurl not in visited and url in newurl:
                visited.append(newurl)
                urls.append(newurl)
                print newurl
    except:
        print "error"
        urls.pop(0)
       
i get the following lines back


martin@linux-3645:~/dev/python> python p1.py
Traceback (most recent call last):
File "p1.py", line 3, in <module>
from bs4 import BeautifulSoup
ImportError: No module named bs4
martin@linux-3645:~/dev/python> 
sure thing - the above mentioned code is version 2 based.

but i guess that i have done some kind of misconfiguration in the installation of python?!?

probably i have choosen some wrong paths...

love to hear from you
Try using pip3 install ... . Since opensuse comes with Python 2 and Python 3 preinstalled, you you need to specify which version you are using. If you you installed an additional Python version, (say 3.6.3) you need to reference that, for example pip3.6 install ...
hello dear - sparkz - alot,

many thanks - i runned a final test - now i am going to to what you adviced. Many thanks again


martin@linux-3645:~/dev/python>  python3 p1.py
  File "p1.py", line 31
    print newurl
               ^
SyntaxError: Missing parentheses in call to 'print'
martin@linux-3645:~/dev/python>
how to check and make sure what is going on on the machine!?
apollo, there is a change in how print is used in Python 3 as compared to Python 2. Here is a quick summary.
print newurl is for Python 2, so you will need to change that to:
print(newurl). Same with other print statement you have.
hello dear J crater

many thanks for the heads up and the tipps regarding the difference of Python 2 and 3. I appreciatate this:

one word regarding the system i run here:


1. i have installed a pip package as user when it would most efficiently be done using a prebuilt RPM as root.
2. i thougt that i were using Python 3 - but in fact there is Python 2 (the openSUSE default).


but wait: I have installed Eric verison 5 on my openSuse version 42.3:

and if i open eric i see the following

Quote:Python 3.4.6 (default, Mar 22 2017, 12:26:13) [GCC] auf linux-3645, Standard>