code "from simple_cdd.env import environment" where are these packages? - python-3.x

I can not find import packages localtion.
from simple_cdd.env import Environment
from simple_cdd.variables import VARIABLES
from simple_cdd.exceptions import Fail
from simple_cdd.tools import FancyTerminalHandler
from simple_cdd.utils import run_command,verify_preseed_file,shell_quote,shell_which

It's in the python3-simple-cdd package, which is under:
/usr/lib/python3/dist-packages/simple_cdd

Related

ModuleNotFoundError: No module named 'plotly' but it work from workspace

i have read all the posts related to this topic but i could not find the solution for my case.
In my ubuntu 20.04 I have installed plotly through the command:
pip3 install plotly
and if i launch python3 from command line and if i run:
import plotly.graph_objects as go
it works perfectly. But if i launch the same command from python script "test.py":
#!/usr/bin/python3
# -*- coding: utf-8 -*-
import cgi
import cgitb
from datetime import date, timedelta
import datetime
import time
import numpy as np
import pandas as pd
import os
import calendar
import matplotlib
matplotlib.use('Agg')
import matplotlib.pylab as plt
import plotly.graph_objects as go
it returns the error log:
ModuleNotFoundError: No module named 'plotly'
Anyone can help me? many thanks
Ok, i resolved the issue by installing the module as a root user because in this way Python will try to search for the module’s name in the root directory and not in the usr one
thank you everyone

How to handle importing a package import if it doesn't exist

import os
import re
import fitz # requires fitz, PyMuPDF
import pdfrw
import subprocess
import os.path
import sys
from PIL import Image
In my case fitz doesn't exist since it needs PyMuPDF. Is there a way to tell python to download dependencies and install them if they don't exist?
I am new to python and learning a lot. Apologizes in advance
Using Python 3.9.4
Platform that I am developing on is macOS but will be deploying on Windows
Editor is VSCode
Using try-catch to handle missing package
Ex:
import subprocess
def install(package):
subprocess.call(['pip', 'install', package])
try:
import fitz # requires fitz, PyMuPDF
except:
install('fitz')
A better practice would be to handle this before your code is executed. Example: using a requirements.txt file with all the dependent packages. And running the file before code execution.

Terminal Command to install imported module of a module

Lets assume I have a module say utility.py
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
from datetime import datetime
import os
import random
import sys
import threading
import numpy as np
import tensorflow as tf
.....
I'd like to import this in my drive.py. I have it saved in my local directory and have in my first line
from . import utility
Is that possible, to issue a command in terminal to find the non-local modules ( tensorflow, numpy, etc), and install them using pip?
Any workaround would be appreciated.
CS
If you mean that you'd like the command to parse the file's imports and install missing dependancies automatically, then no it is not possible.
There are modules that are not imported with the pip's package name. For example the package facebook-sdk is imported as import facebook, making impossible to deduct the package name from the import.

while import resnet got error - ImportError: cannot import name '_obtain_input_shape''

I got an while importing resnet.
I tried removed latest version and install old version of keras==1.0.6 and it doesn't work. Also i did changes in resnet.py --> "from keras_applications.imagenet_utils import _obtain_input_shape , i got an error an like "ImportError: cannot import name 'GlobalMaxPooling2D' "
from keras.applications.imagenet_utils import _obtain_input_shape
import os
import numpy as np
from pickle import dump
import resnet
import numpy as np
from keras.preprocessing.image import load_img, img_to_array
from keras.models import Model
from os import listdir
import cv2
from keras import applications
I need import all these without an error. kindly help me to sort this. Thanks in advance
Change
from keras.applications.imagenet_utils import _obtain_input_shape
with
from keras_applications.imagenet_utils import _obtain_input_shape

Android studio unable to import WearableExtender NotificationManagerCompat and RemoteInput

I have a project class with the following imports:
import android.app.Activity;
import android.app.Fragment;
import android.app.Notification;
import android.app.PendingIntent;
import android.app.RemoteInput;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.support.v4.app.NotificationCompat;
import android.support.v4.app.NotificationCompat.Action;
import android.support.v4.app.NotificationCompat.WearableExtender;
import android.support.v4.app.NotificationManagerCompat;
import android.support.v4.app.RemoteInput;
import android.text.Html;
import android.util.Log;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
In android studio the following three bring up a 'cannot resolve symbol' error:
import android.support.v4.app.NotificationCompat.WearableExtender;
import android.support.v4.app.NotificationManagerCompat;
import android.support.v4.app.RemoteInput;
Wierdly, the import for NotificationCompat and NotificationCompat.Action in android.support.v4.app are successful
import android.support.v4.app.NotificationCompat;
import android.support.v4.app.NotificationCompat.Action;
I have tried to use the same imports on eclipse (pointing to the same SDK as android studio) and the same worked and ran without any errors.
I've also tried Minto's solution of invalidating caches/restarting android studio ...my SDK is up to date as at the time of posting. Thanks for any help in advance
Make sure that you put the following entry into your application's build.gradle file to provide the necessary dependencies:
dependencies {
compile 'com.android.support:support-v4:20.0+'
}
The version number is important, if you specify an older version it will be missing the new Notification code for wearables.
Google has moved some of these tools into the standard libraries. For example, WearableExtender is in Android.app.Notification now. Try ditching the import statements giving you problems, and let Android Studio suggest what to import. Lots of Google's guides have outdated or otherwise incorrect code right now, as they have recently rolled out Google Play Services 5 and other official releases of preview products.

Resources