Newbie Declaring (File_Path, Import Error Question)

Hi Team

Long time VBA programmer just jumping into the deep end of the Python pool using v(3.9.1). I am using Anaconda’s Jupyter Notebook for compiling.

I also [pip] Installed (Pandas, MatPlotLib, RBase) and a couple of other library modules on the off chance I become an overnight Python Programming senstaion… :slightly_smiling_face: (Not likely!)

I appreciate Python is structured different to VBA, particularly the use of [Importing] as opposed to [Dim] for declaring.

I’m just playing around with some examples I found on youtube and have an issue with a line in the following code which is typed exactly the same as presenter’s code and his seems to work just fine:

As I have zero idea how to debug Python Code, di I need to declare my os (Operating System) or at least, my Systems Environment so the code can navigate the second line of the code???

In [ ]: 1 import numpy as np
       2 import pandas as pd

       3 import os

       4 import urllib

       5 %matplotlib inline

In [ ]: 1 url = “https://covid19.who.int/WHO-COVID-19-Global-Data.csv

       2 file_path = os.path.join("Data", "Covid")

NameError Traceback (most recent call last)
in
1 url = “https://covid19.who.int/WHO-COVID-19-Global-Data.csv
----> 2 file_path = os.path.join(“Data”, “Covid”)

NameError: name ‘os’ is not defined

As always
TIA
Mark

Hi Mark, and welcome!

I’m afraid that your example code doesn’t make sense to me, and neither
does the error message you are getting.

I’m not an expert on Jupyter or iPython, but I expect that the prompts
you should see should look more like this:

In [1]: line of code

In [2]: line of code

In [3]: line of code

etc, not the way you show them:

In []: 1 line of code

       2 line of code

       3 line of code

That second batch doesn’t make sense to me, it looks like it should be a
syntax error.

Did you re-type the lines of code from memory? Or edit them in any way?
If so, can you please copy and paste them from your Jupyter session
so we can see exactly what they are. (Don’t forget to format them as
code when you post, there’s a button on the web interface that does
that, or if replying to email you can format code with three back-ticks
before and after your code:

```
paste code here
```

Normally I very strongly recommend people copy and paste the text of
their code, but in this case I wonder if it might be helpful to also see
a screenshot of your Jupyter notebook, complete with the imports, the
line of code that fails, and the full exception.

The secret to debugging is to simplify the code that you have to work
with. You are reporting an error:

NameError: name 'os' is not defined

but you showed code that apparently imported os, so I am flummoxed how
you could get that error.

Try this: open a new notebook, and run these two lines of code:

import os
print(os.path.join("Data", "Covid"))

Please copy and paste your input and output from this.

Hi Steven

Thank you for your warm welcome and response. I Apologise for not responding earlier. I was holidaying with family.

So! It turns out I was using the wrong Assembly platform, hence the reason it did not understand what I was trying to do.

I have watched a few more tutorial video’s and understand it a little more than prior. It will no-doubt take me some time to transition from my VBA (Linear) thinking.

I can move forward confidently in the knowledge there are Forum members at hand to help when I feel the need to smash my head against the wall :slight_smile:

Thanks again
Regards
Mark.

G’day Steven

I decided to ditch the Anaconda Platform and just use Python / Idle.

I have ([PIP] reinstalled) all the modules I feel I will need, one of the foremost ones being [MatPlotLib], which installed/reintalled with zero issues, but!

I keep getting an error when I run the following code:

(from:https://www.youtube.com/watch?v=afITiFR6vfw)

import random
import matplotlib.pyplot as plt
from matplotlib import style

style.use(‘fivethirtyeight’)

fig = plt.figure()

def create_plots():
xs = [ ]
ys = [ ]

for i in range(10):
    x = i
    y = random.randrange(10)

    xs.append(x)
    ys.append(y)
return xs, ys

ax1 = fig.add_subplot(211)
ax2 = fig.add_subplot(212)

x,y = create_plots()
ax1.plot(x,y)

x,y = create_plots()
ax2.plot(x,y)

plt.show

Now I get an error pointing to matplotlib:
================= RESTART: C:/Users/Me/pyProj/my_pyEnv/MyPy.py =================
Traceback (most recent call last):
File “C:/Users/Me/pyProj/my_pyEnv/MyPy.py”, line 2, in
import matplotlib.pyplot as plt
ModuleNotFoundError: No module named ‘matplotlib’

==========================================================================
Any assistance is appreciated

Cheers
Mark.