Python module loading with Spyder - python

I am new to using Python for machine learning and I am trying to learn ZhuSuan using Spyder.
I have downloaded and installed Zhusuan as descibed here: https://zhusuan.readthedocs.io/en/latest/.
I have also tried installing the additional dependencies required for the examples by following the instructions here: https://github.com/wmyw96/ZhuSuan.
I then try and run an example script (eg https://github.com/thu-ml/zhusuan/blob/master/examples/bayesian_neural_nets/bayesian_nn.py), importing the modules as with the code:
from __future__ import absolute_import
from __future__ import print_function
from __future__ import division
import os
import tensorflow as tf
from six.moves import range, zip
import numpy as np
import zhusuan as zs
from examples import conf
from examples.utils import dataset
However, on execution, I receive the following error:
File "C:/*******/bayesian_nn.py", line **, in <module>
from examples import conf
ModuleNotFoundError: No module named 'examples'
I would be very grateful if anyone could anyone help identify where I have gone wrong with loading or importing the example modules.
Many thanks in advance.
Ross

I have solved the problem. The additional dependencies had not installed correctly for some reason. Running a full reinstall fixed the problem, and the program now runs successfully with the original code. Thanks to Carlos for his comment.

Related

How do i import edi-835-parser in python

I have pip installed edi-835-parser and then trying to import like below
from edi_835_parser import parse
but getting module not found error.
as per edi-835-parser documentation package name is edi-835-parser but while importing it is edi_835_parser
Also tried using below code.
import importlib
module_name = importlib.import_module('edi-835-parser')
This also did not help much.
Could someone help on this

VimbaPython relative import

Im trying to use vimbapython. every time I run anything that imports vimba import vimba the following error occurs:
from .c_binding import call_vimba_c, VIMBA_C_VERSION, VIMBA_IMAGE_TRANSFORM_VERSION, \
ImportError: attempted relative import with no known parent package
modules and drivers are all freshly installed.
Did anybody encountered something like that?

No module named 'netCDF4'

I am currently working with netCDF data in the Spyder IDE, however when I try to import 'Dataset' from the module
from netCDF4 import Dataset
it is giving me the following error: "No module named 'netCDF4'". I already installed the module but I guess it is not in the same environment where I installed spyder. How can I fix this? If it helps solving my question. When I try to install netCDF4 in the spyder console using 'pip install netCDF4' it gives the following error:
"/Applications/Spyder.app/Contents/MacOS/python: No module named pip
Note: you may need to restart the kernel to use updated packages."
I looked up the path of the module: '/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/netCDF4'
and I guess the path for spyder is:
'/Applications/Spyder.app/Contents/MacOS/python'
How can I make sure that they are both located in the same environment?
I tried to look up the issue, however nothing really solved my problem.
Would be glad if anyone could help me out.
import matplotlib.pyplot as plt
import pandas as pd
import numpy as np
from netCDF4 import Dataset
from cftime import numb2date
import tifffile as tifffile
# define arrays
XNR=[] # number
Xdt=[] # time
YGP=[] # GPP
YPP=[] # PPFD
# read csv file and extract column 0 (timestemp), PPFD (column 54) and GPP (column 312)
# take a file from FLUXNET for validation of the GPP model
with open(r'/Users/janoschbeer/Documents/Studium/ESS/ES_Observ/Assignments/Lab6/FLX_SJ-Adv_FLUXNET2015_SUBSET_2011-2014_1-4/FLX_SJ-Adv_FLUXNET2015_SUBSET_DD_2011-2014_1-4.csv') as csv:
lines = csv.readlines()
for i in range(2, len(lines)):
tmp=lines[i].split(",")
XNR.append(float(i))
Xdt.append(float(tmp[0]))
YGP.append(float(tmp[312]))
YPP.append(float(tmp[54]))

ImportError: cannot import name 'TwitterPreprocessor' from 'preprocessor'

I am installing the package for data-cleaning purpose,
!pip install tweet-preprocessor
from preprocessor import TwitterPreprocessor
I am using both Jupyter and Colab, there is no issue using in Jupyter. But still, receiving this issue in colab:
ImportError: cannot import name 'TwitterPreprocessor' from 'preprocessor' (/usr/local/lib/python3.7/dist-packages/preprocessor/init.py)
Please help me with this problem to correct.
Thank you
The library tweet-preprocessor simply doesn't have the TwitterPreprocessor you're trying to import. Take a look at the GitHub repo - no TwitterPreprocessor in sight.
It's suggested to import it via: import preprocessor as p (or import one of the said names from the GitHub repo). You can look at the __init__.py what names you're able to import.
ImportError: cannot import name 'TwitterPreprocessor' from 'preprocessor' ([...]\preprocessor\_init_.py)

How can I bundle a Python script with module dependencies into a package or .exe file?

I have following dependencies for my script
from sqlalchemy import create_engine
import pandas as pd
import numpy as np
from scipy import sparse
from sklearn import neighbors
import itertools
import math
import time
PATH_XGBOOST = "./xgboost/wrapper/"
PATH_MODEL = './models/model.model'
import sys
sys.path.insert(1,PATH_XGBOOST)
import xgboost as xgb
For this script I wouild like to package all the stuff and run it on another machine without any package or library installation but only python installed. (preferably package on Linux and run on Windows) Is there any way to do so ? As far as I search there are pyinstaller and py2exe but I cannot deal with them, I guess due to the xgboost libaray.
Try cx_freeze
If you want to freeze using distutil script follow this steps

Categories

Resources