LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   learning and installing Python 3 (https://www.linuxquestions.org/questions/programming-9/learning-and-installing-python-3-a-4175580011/)

rblampain 05-17-2016 10:29 AM

learning and installing Python 3
 
I need to write "trow-away" scripts (or scripts to be used only once) but for UTF-8 files and it seems that Python 3 is much better than Python 2.7 (which comes with my Debian 7 distro) for that purpose so I have followed a "how to" from a Ubuntu forum explaining how to download and install Python-3.3.5 with the following instructions for which I have absolutely no experience:

Code:

wget http://www.python.org/ftp/python/3-3.5/Python-3-3.5.tar.xz
tar xJf ./Python-3-3.5.tar.xz
cd ./Python-3-3.5
./configure --prefix=/opt/python3-3
make && sudo make install

Python-3.3.5 was installed successfully in
Code:

/home/user_x/Python-3.3.5
and
/opt/python3.3/bin

with no problem but after changing the first line of a Python 2.7 script to
Code:

#!/home/user_x/Python-3.3.5
or
#!/opt/python3.3/bin

I get the message:
Code:

bash: ./test.py: /home/user_x/Python-3.3.5: bad interpreter: Permission denied
or
bash: ./test.py: /opt/python3.3/bin: bad interpreter: Permission denied

This is even after "chown" everything owned by root in /home/user_x/Python-3.3.5 and /opt/python3.3/bin to "user_x" and giving directory ~/Python-3.3.5/ permissions 777
Both text.py and the directory Python-3.3.5 (and its files) belong to the same user_x and group user_x. There is 2 larges files as below and subdirectory "Python" contains all the .c .h .o files.
Code:

-rw-r--r--  1 user_x user_x 17304682 May 17 21:43 libpython3.3m.a
-rwxr-xr-x  1 user_x user_x 10180893 May 17 21:43 python
drwxr-xr-x  2 user_x user_x    4096 May 17 21:43 Python

This is contents of /opt/python3.3/bin:
Code:

lrwxrwxrwx 1 root root              8 May 17 21:45 2to3 -> 2to3-3.3
-rwxr-xr-x 1 user_x user_x      105 May 17 21:45 2to3-3.3
lrwxrwxrwx 1 root root              7 May 17 21:45 idle3 -> idle3.3
-rwxr-xr-x 1 user_x user_x      103 May 17 21:45 idle3.3
lrwxrwxrwx 1 root root              8 May 17 21:45 pydoc3 -> pydoc3.3
-rwxr-xr-x 1 user_x user_x        88 May 17 21:45 pydoc3.3
lrwxrwxrwx 1 root root              9 May 17 21:45 python3 -> python3.3
-rwxr-xr-x 2 user_x user_x 10180893 May 17 21:44 python3.3
lrwxrwxrwx 1 root root            17 May 17 21:45 python3.3-config -> python3.3m-config
-rwxr-xr-x 2 user_x user_x 10180893 May 17 21:44 python3.3m
-rwxr-xr-x 1 user_x user_x    1982 May 17 21:45 python3.3m-config
lrwxrwxrwx 1 root root      16 May 17 21:45 python3-config -> python3.3-config
lrwxrwxrwx 1 root root      10 May 17 21:45 pyvenv -> pyvenv-3.3
-rwxr-xr-x 1 user_x user_x      240 May 17 21:45 pyvenv-3.3

Could anyone tell me what could be wrong?

Thank you for your help.

HMW 05-17-2016 11:05 AM

I have no idea what kind of guide you followed, but it is TERRIBLE!

The way to install Python 3 on Debian is:
Code:

sudo apt-get install python3
Or if you haven't configured sudo, as root:
Code:

apt-get install python3
Do this, and then issue this command:
Code:

which python3
If all is well you should see:
Code:

which python3
/usr/bin/python3

The version in the repos for Debian 7 is Python 3.2 by the way.

Once you get Python 3 installed correctly, you can use this at the beginning of your files:
Code:

#!/usr/bin/env python3
Best regards,
HMW

Edit: I forgot to say, "good luck and happy hacking!" Python 3 is my go-to lagnuage these days when a bash script simply isn't enough. Go for it and have fun!

ntubski 05-17-2016 11:18 AM

Quote:

Originally Posted by rblampain (Post 5546771)
Python-3.3.5 was installed successfully in
Code:

/home/user_x/Python-3.3.5
and
/opt/python3.3/bin

with no problem but after changing the first line of a Python 2.7 script to
Code:

#!/home/user_x/Python-3.3.5
or
#!/opt/python3.3/bin


You need a filename after the "#!", not a directory name, e.g.
Code:

#!/opt/python3.3/bin/python3

rblampain 05-18-2016 01:29 AM

Thank you for the answers.
Quote:

You need a filename after the "#!", not a directory name, e.g.
was the solution.


All times are GMT -5. The time now is 04:01 AM.