Python Forum
Code is not running on Windows
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Code is not running on Windows
#1
Hello,

First of all, I am a total newbie by all means to python. I do know pascal (Delphi, Lazarus) but no experience of python at all.

I am using Windows 10 64bit. I have installed pyhton on my computer. I also installed numpy on my system to test below scripts.

I try to run a pyhton script that I got from a github repository. As this is being my first ever post. Forum is not allowing me to share links.

There are more than one file and more than one directory. Base directory structure is something like below:
C:\baby_cry_detection-master>dir
 Volume in drive C has no label.
 Volume Serial Number is 2E81-FCFE

 Directory of C:\baby_cry_detection-master

19.04.2017  05:26    <DIR>          .
19.04.2017  05:26    <DIR>          ..
19.04.2017  05:26             1.072 .gitignore
19.04.2017  05:26    <DIR>          data
11.05.2017  06:07    <DIR>          pc_main
11.05.2017  06:07    <DIR>          pc_methods
19.04.2017  05:26             1.081 README.md
19.04.2017  05:26    <DIR>          rpi_main
19.04.2017  05:26    <DIR>          rpi_methods
19.04.2017  05:26             1.170 run_crying_detection.sh
19.04.2017  05:26               588 setup.py
               4 File(s)          3.911 bytes
               7 Dir(s)   7.987.707.904 bytes free

C:\baby_cry_detection-master>
I need to run several scripts before I can start using actual program. When I try to run very first script that I should be running, I get following error:
C:\baby_cry_detection-master>python pc_main\train_set.py
Traceback (most recent call last):
  File "pc_main\train_set.py", line 10, in <module>
    from pc_methods import Reader
ModuleNotFoundError: No module named 'pc_methods'

C:\baby_cry_detection-master>
train_set.py is not a big file and it includes following lines:
C:\baby_cry_detection-master\pc_main>type train_set.py
# -*- coding: utf-8 -*-

import argparse
import os
import numpy as np
import logging
import re
import timeit

from pc_methods import Reader
from pc_methods.feature_engineer import FeatureEngineer


def main():
    parser = argparse.ArgumentParser()
    parser.add_argument('--load_path',
                        default='%s/../data' % os.path.dirname(os.path.abspath(__file__)))
    parser.add_argument('--save_path',
                        default='%s/../../output/dataset/' % os.path.dirname(os.path.abspath(__file__)))
    parser.add_argument('--log_path',
                        default='%s/../' % os.path.dirname(os.path.abspath(__file__)))

    # Arguments
    args = parser.parse_args()
    load_path = args.load_path
    save_path = args.save_path
    log_path = args.log_path

    ####################################################################################################################
    # Set up logging
    ####################################################################################################################

    logging.basicConfig(format='%(asctime)s - %(levelname)s - %(message)s',
                        datefmt='%Y-%m-%d %I:%M:%S %p',
                        filename=os.path.join(log_path, 'logs_pc_methods_feat_eng.log'),
                        filemode='w',
                        level=logging.INFO)

    ####################################################################################################################
    # READ FILES IN SUB-FOLDERS of load_path and FEATURE ENGINEERING
    ####################################################################################################################

    # list load_path sub-folders
    regex = re.compile(r'^[0-9]')
    directory_list = [i for i in os.listdir(load_path) if regex.search(i)]

    # initialize empty array for features
    X = np.empty([1, 18])

    # initialise empty array for labels
    y = []

    logging.info('Creating training set...')
    start = timeit.default_timer()

    # iteration on sub-folders
    for directory in directory_list:

        # Instantiate FeatureEngineer
        feature_engineer = FeatureEngineer(label=directory)

        file_list = os.listdir(os.path.join(load_path, directory))

        # iteration on audio files in each sub-folder
        for audio_file in file_list:
            file_reader = Reader(os.path.join(load_path, directory, audio_file))
            data, sample_rate = file_reader.read_audio_file()
            avg_features, label = feature_engineer.feature_engineer(audio_data=data)

            X = np.concatenate((X, avg_features), axis=0)
            y.append(label)

    # X.shape is (401, 18) as I'm not using indexing. First line is made of zeros and is to be removed
    X = X[1:, :]

    stop = timeit.default_timer()
    logging.info('Time taken for reading files and feature engineering: {0}'.format(stop - start))

    ####################################################################################################################
    # SAVE
    ####################################################################################################################

    logging.info('Saving training set...')

    # Save to numpy binary format
    np.save(os.path.join(save_path, 'dataset.npy'), X)

    np.save(os.path.join(save_path, 'labels.npy'), y)

    logging.info('Saved! {0}'.format(os.path.join(save_path, 'dataset.npy')))
    logging.info('Saved! {0}'.format(os.path.join(save_path, 'labels.npy')))


if __name__ == '__main__':
    main()

C:\baby_cry_detection-master\pc_main>
I have tried to contact developer, but she's using that code on Raspberry Pi and I am having problems on Windows. She tried to help, but I still cannot run the script. Our conversation is in the issues part of the repository (First post limitations, I cannot provide an url).

Briefly, "pc_methods" mentioned in above error message is a directory that should be somehow imported in the initial script. But, I do not know how to do that.

Lastly, directory of pc_main includes a zero byte sized "__init__.py" file. I do not know what it does, just want to provide as much information as possible.

I do appreciate any help to get me running that script, please.

Thanks & regards,
Ertan
Reply
#2
looks like this is the github repo OP refers to

https://python-forum.io/Thread-Code-is-n...on-Windows

But it's too late here and I don't have time to look into it
Reply
#3
The original was for raspberry-pi
it requires:
numpy, pandas, sklearn, pickle, json, pydub and librosa
If you get my package to show installed packages see: https://python-forum.io/Thread-Show-Inst...age-detail
it will shw you what you have installed.

for those that aren't, you can get using
pip install packagename
Reply
#4
I finally got a Raspberry Pi device to do some tests. Unfortunately, same error displayed on Raspberry Pi, too.
pi@raspberrypi:~/baby_cry_detection-master $ python rpi_main/make_prediction.py Traceback (most recent call last):
  File "rpi_main/make_prediction.py", line 11, in <module>
    from rpi_methods import Reader
ImportError: No module named rpi_methods
pi@raspberrypi:~/baby_cry_detection-master $ ls
data     pc_methods  rpi_main     run_crying_detection.sh
pc_main  README.md   rpi_methods  setup.py
pi@raspberrypi:~/baby_cry_detection-master $
This seems to be a simple importing of another python script in another directory. I do not know how to do that.
Reply
#5
Would I be correct in presuming you are referring to this site: baby_cry_detection ?  (I could not find it on PyPi). A quick glance shows it is clearly targeted towards the Raspberry Pi and presumably the Raspbian OS.  There doesn't seem to be any instructions on how to install it, where to install it, what Python versions it's compatible with, etc.

As to your problem, I believe by default, Python will only import from it's current directory, though you could probably try a "sys.path.insert(0, path)" before trying to import the module. Ideally, she would have created an "__init__" file.
If it ain't broke, I just haven't gotten to it yet.
OS: Windows 10, openSuse 42.3, freeBSD 11, Raspian "Stretch"
Python 3.6.5, IDE: PyCharm 2018 Community Edition
Reply
#6
I found the same repo and only just now I see that I post wrong link the other day :-) It was late indeed :-)
Reply
#7
(Aug-04-2017, 01:31 PM)sparkz_alot Wrote: Would I be correct in presuming you are referring to this site: baby_cry_detection ?  (I could not find it on PyPi). A quick glance shows it is clearly targeted towards the Raspberry Pi and presumably the Raspbian OS.  There doesn't seem to be any instructions on how to install it, where to install it, what Python versions it's compatible with, etc.

As to your problem, I believe by default, Python will only import from it's current directory, though you could probably try a "sys.path.insert(0, path)" before trying to import the module. Ideally, she would have created an "__init__" file.

That's the right site :)

Yes, she's using that software on Raspberry Pi. However, there are files for Windows as far as I can see. There is no install instructions. You simply get all repository in a directory and run commands in my earlier posts for preparing sound analysis files. I couldn't get over that stage yet.

There are "__init__.py" files. However, as I already indicated, all of them are empty zero byte files. Nothing in them. If it is easier to use __init__, I very much would like to learn how?

Thanks.
Reply
#8
for basic info about packages you may refer to docs
https://docs.python.org/3/tutorial/modul...l#packages
Quote:The __init__.py files are required to make Python treat the directories as containing packages; this is done to prevent directories with a common name, such as string, from unintentionally hiding valid modules that occur later on the module search path. In the simplest case, __init__.py can just be an empty file, but it can also execute initialization code for the package or set the __all__ variable, described later.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Newbie at using python and tensorflow getting error when running simple code FeatherineAu 0 3,998 Sep-28-2018, 02:09 PM
Last Post: FeatherineAu
  how to reduce running time of the code dilmailid 6 4,022 May-18-2018, 02:49 AM
Last Post: scidam

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020