Can anyone out there help me with setting up and running a program in Python?

A few weeks ago I found an article showing me how to create discreet graphs out of large data sets. I downloaded 2 files; one a tgz file and the other text for what might be further terminal commands. Next I was asked to type the following commands into the terminal:

python3 -m pip install matplotlib
python3 -m pip uninstall numpy
python3 -m pip install numpy==1.12.1

The first command produced the following:

/usr/bin/python3: No module named pip

I think I understand what I’m being told: “pip” is a Python module needed to download and install more Python modules. Apparwently the python version Linux Mint 18.3 does not include it. So I tried:

curl -O https://bootstrap.pypa.io/get-pip.py

and then:

sudo python get-pip.py

It seemed to install properly, but when I tried the first command again I got the same message as before. And indeed I couldn’t find “pip” in /usr/bin/python3 on visual inspection.

So, If there are any Python jockeys out there who can give me a few pointers I’d be most grateful!

I advise you do read the documentation, before installing from an external source.

Warning

Be cautious if you are using a Python install that is managed by your operating system or another package manager. get-pip.py does not coordinate with those tools, and may leave your system in an inconsistent state.

https://pip.pypa.io/en/stable/installing/

Therefore you should go for:

apt policy python-pip

if that looks something like

python-pip:
  Installed: none
  Candidate: 9.0.1-2+rpt2
  Version table:
 *** 9.0.1-2+rpt2 500
        500 https://archive.raspberrypi.org/debian stretch/main armhf Packages
        100 /var/lib/dpkg/status
     9.0.1-2 500
        500 http://raspbian.raspberrypi.org/raspbian stretch/main armhf Packages

then you can safely go for:

sudo apt install -y python-pip

2 Likes

Thanks Akito!

I didn’t expect such a prompt response! Yeah, I was dimly aware that the system needs its own versions of Python and that it’s not a good idea to screw around. I always planned to use Timeshift to revert Python to its original state.

My output for: apt policy python-pip was:

dave@dave-BT434AAR-ABA-s5603w ~ $ apt policy python-pip
python-pip:
Installed: (none)
Candidate: 8.1.1-2ubuntu0.4
Version table:
8.1.1-2ubuntu0.4 500
500 http://mirror.csclub.uwaterloo.ca/ubuntu xenial-updates/universe amd64 Packages
500 http://mirror.csclub.uwaterloo.ca/ubuntu xenial-updates/universe i386 Packages
8.1.1-2 500
500 http://mirror.csclub.uwaterloo.ca/ubuntu xenial/universe amd64 Packages
500 http://mirror.csclub.uwaterloo.ca/ubuntu xenial/universe i386 Packages

So I guess I can try to install “pip” again, but only after a restore.

I’ll post the results soon. Thanks again!

Dave.

2 Likes

What happens when you type “python --version” and/or “python3 --version”
does it say something like …
Python 2.7.15rc1
or
Python 3.6.6

Which is your default ?
If you need to type 3 to get python3 2.7 is your default
type “python” the version is on the top line, to exit ‘ctrl’+‘d’
OR
whereis python
This shows the order of execution mine is 2.7 first

BUT If you want to install/run on python3 you can use pip3 which ensures the library only installs and is available to python3

1 Like

This is unimportant, because his initial commands that he copied from the tutorial already circumvent this issue.

Hey Guys, thanks for your attention!

That turned out to be the case exactly. In each case I did actually install pip–just not pip3. Late last night I found I’m running Python 2.7.12. I then opened Synaptic to see what clusters around pip and saw “python3 pip”, and installed it from there. Once done, matplotlib and numpy 1.12.1 installed easily from the terminal.

Once I know I can consistently launch this program I’ll revert to my proper version of pip.

I’d love to say that that settles everything, but I hit a further snag while trying to install the program. after downloading a tgz file and placing it in home, I entered the command:

tar xzvf GHCNPY.tgz

and got:

GHCNPY/
GHCNPY/ghcn.py
GHCNPY/ghcnd-inventory.txt
GHCNPY/ghcnd-stations.txt
GHCNPY/Toto.png
GHCNPY/US.txt
dave@dave-BT434AAR-ABA-s5603w ~ $ cd GHCNPY
dave@dave-BT434AAR-ABA-s5603w ~/GHCNPY

So a proper folder has been created. In a second download is a text file labelled “get” which I assumed is a series of commands. They look like this:

#!/bin/tcsh
make
curl -O ftp://ftp.ncdc.noaa.gov/pub/data/ghcn/daily/ghcnd_hcn.tar.gz
curl -O ftp://ftp.ncdc.noaa.gov/pub/data/ghcn/daily//ghcnd-stations.txt
tar xzvf ghcnd_hcn.tar.gz
cd ghcnd_hcn
cat *.dly > US.txt
ln -s …/ghcn.exe
ln -s …/ghcnd-stations.txt
cp -f *.dly /c/Users/User/PullingBackTheCurtain/

The first command seems to work, but it doesn’t like the second.

dave@dave-BT434AAR-ABA-s5603w ~ $ cd GHCNPY
dave@dave-BT434AAR-ABA-s5603w ~/GHCNPY $ #!/bin/tcsh
dave@dave-BT434AAR-ABA-s5603w ~/GHCNPY $ make
make: *** No targets specified and no makefile found. Stop.

At this point I feel like I’m too close to quit.

Any ideas?

This isn’t just a text file, it is a script. From the first line you see that it requires tcsh which is normal for BSD-like systems, but far from normal in Debian derivatives. That said, you could change the first line from #!/bin/tcsh to #!/bin/bash, because the rest of the commands seem to be available in our shell, as well. So much for the theory. In practice, this means that your tutorial is not for Ubuntu systems or at least this script isn’t. So even if this script alone works, it may be that the other things you already did, won’t work, if they are specifically explaining how it should work on a BSD-like system and not Ubuntu.

As for the pip version: if you download pip, you already have both versions. You select the correct version by typing python3 -m pip, which you already did in the first place, so you wouldn’t need to worry about this.

Actually what I’ve been doing is restoring python to it’s original state with Timeshift. So each time I’m starting fresh. Once I’ve worked out a procedure I plan to erase all traces of it and run the plots from another machine.
But thank you for your concern and your knowledge.

This makes some sense. The page is labelled “for linux/mac”. Mac would use BSD like commands. It could be the author figured it might work in linux as well.

I don’t know what you mean by calling it a script. Other than feeding it line by line into the terminal, is there any other way of loading it?

Also the command that actually stopped me was “make”. It produces the message: “make: *** No targets specified and no makefile found. Stop.”

Macs usually use the zsh so don’t know why the tutorial says linux/mac, since both are not that correct.

What is a (bash) script?

Anything you can run normally on the command line can be put into a script and it will do exactly the same thing. Similarly, anything you can put into a script can also be run normally on the command line and it will do exactly the same thing.

Except the first line that always starts with #!.

It failed at make, because it wasn’t executed in the correct directory. The tutorial has to tell you which directory it has to be executed in.

Thanks for your help so far. I’m going to see if I can contact the author! If I run it all as a script it skips over the “make” command and offers possible commands, but it does execute the rest of the script, except the final one. I think the directories aren’t set up properly.

But thanks again for your help so far!

1 Like

make needs a file with a name like makefile to tell it what to compile and possibly download and install
which would be platform specific also
Normally a developer provides some form of readme to give some hints/steps on installing the code

It’s designed to under windows were you expecting that ?