Error with import script in colaboratory - python-3.x

When I try to import a script that is in the same folder as the colaboratory
then I get an error:
ImportErrorTraceback (most recent call last)
<ipython-input-8-e7a4315427c8> in <module>()
----> 1 import translate
ImportError: No module named translate
The path and location of the file checked!!!

Colab doesn't automatically load any files from your Google Drive folder; you'll need to copy the files locally (eg with something like https://colab.research.google.com/notebooks/io.ipynb#scrollTo=P3KX0Sm0E2sF and then saving to a file).

Related

How to import files in other Folder in Python

I'm using Python 3.10.
I have the following directory:
folder project
The File parse-subfinder.py , has a code:
parse-subfinder
But I get the error:
Traceback (most recent call last):
File "c:\Users\Windows\Desktop\smart-recon\subdomains\parse-subfinder.py", line 2, in
from ..utils.directory import Directory
ImportError: attempted relative import with no known parent package
How can I make this work?
I tried:
from ..utils.directory import Directory
from ..utils.discover import Discover

Import script in sub directory not working... Blender Add-On

I have a folder structure like this:
C:
|_Blueprint
│ main.py
│
└───toolbox
blueprint_tools.py
When I run this code in Blender's scripting text page:
from toolbox.blueprint_tools import dimension, array, modify
I get an error in the console
Traceback (most recent call last):
File "\main.py", line 20, in <module>
ModuleNotFoundError: No module named 'toolbox'
Error: Python script failed, check the message in the system console
I swear, when I run this code (on other projects) outside of Blender this structure and code runs fine. But I get an error when running this script in Blender for testing out my Add-On.
If I compile the Blueprint folder into a .zip and install it everything works fine.... ??
I'm lost, could anyone please help me.
If I run the code like this: (added a . before toolbox for CWD)
from .toolbox.blueprint_tools import dimension, array, modify
Traceback (most recent call last):
File "\main.py", line 20, in <module>
ImportError: attempted relative import with no known parent package
Error: Python script failed, check the message in the system console
Both your error traces write File \main.py ... which means that Blender considers your main.py file to be in the root folder, knowing nothing about its real location in the file system hierarchy.
When you installed your structure as a zip file, you provided all necessary info to Blender.
Addendum:
Temporarily, during developing / debugging your add-on, you may add the full path (for finding your toolbox.blueprint_tools module) to the sys.path variable.
There are 2 possibilities how to do it:
Insert into your main.py file these commands (use the path to your parent folder of your toolbox folder, of course):
import sys
sys.path += [r"C:\Users\Davi\Documents\Python\PARENT_of_toolbox"]
before your statement
from toolbox.blueprint_tools import dimension, array, modify
command, or
Insert into your main.py file these commands (use the path to your toolbox folder, of course):
import sys
sys.path += [r"C:\Users\Davi\Documents\Python\PARENT_of_toolbox\toolbox"]
before your modified statement
from blueprint_tools import dimension, array, modify

ImportError: No module named 'yolo_utils'

I downloaded openCV and YOLO weights, in order to implement object detection for a certain project using Python 3.5 version.
when I run this code:
from yolo_utils import read_classes, read_anchors, generate_colors, preprocess_image, draw_boxes, scale_boxes
from yad2k.models.keras_yolo import yolo_head, yolo_boxes_to_corners, preprocess_true_boxes, yolo_loss, yolo_body
The console gives the error below:
ImportError Traceback (most recent call
last) in ()
----> 1 from yolo_utils import read_classes, read_anchors, generate_colors, preprocess_image, draw_boxes, scale_boxes
2 from yad2k.models.keras_yolo import yolo_head, yolo_boxes_to_corners, preprocess_true_boxes, yolo_loss, yolo_body
ImportError: No module named 'yolo_utils'
Note that i downloaded yolo_utils.py in the weights folder, how can I fix this issue?
Actually You are Importing user built module. As Yolo_utils is created by a Coursera coordinators to make things easy, this module is available in only their machines and You are trying to import this in your machine.
Here is github link of module :
https://github.com/JudasDie/deeplearning.ai/blob/master/Convolutional%20Neural%20Networks/week3/yolo_utils.py
Save this To your local machine in .py formet
And Copy this file in your lib files of Your application(anaconda or any other)
Copy the source code of yolo_utils .
Paste it in your source code before importing yolo_utils.
It worked for me.
Hope this will help..

Python module doesn't find file include in MANIFEST.in

So I have made a small gui application using pygobject.
Works fine and all when executed from the directory.
Tried to make a python package out of it but get this error everytime:
In [2]: pygofortune.pygofortune.main()
---------------------------------------------------------------------------
Error Traceback (most recent call last)
<ipython-input-2-1e2e05b4c484> in <module>()
----> 1 pygofortune.pygofortune.main()
/usr/lib/python3.5/site-packages/pygofortune-0.1-py3.5.egg/pygofortune/pygofortune.py in main()
55 def main():
56 builder = Gtk.Builder()
---> 57 builder.add_from_file("fortune.glade")
58 builder.connect_signals(Handler())
59 global win, buffer, about
Error: g-file-error-quark: Failed to open file 'fortune.glade': No such file or directory (4)
I had include the files in MANIFEST.in.
The files were present in the sitepackages folder of package too.
Any ideas what I may have done wrong
A filename without a path component will be looked for relative to the current working directory, not the directory where the Python script is installed.
I suggest using something like the pkg_resources feature of Setuptools to install your data files to a known location and retrieve their paths at runtime.

How to setup SublimeREPL to load current working directory

I have installed ipython jupyter console for sublimeREPL using the link https://gist.github.com/MattDMo/6cb1dfbe8a124e1ca5af
However, I face a problem, when I start the "Jupyter Console", it doesn't load the current directory in which I am working.
For Instance, I am working on a file "text.py in directory "/home/sam/desktop/programs/" and I run a manual import "import text" in the sublimeREPL (jupyter console), I get a module not found error
ImportError Traceback (most recent call last)
<ipython-input-3-0660e90ee9d4> in <module>()
----> 1 import text
ImportError: No module named text
I refered to the link Set working directory to location of active script in SublimeREPL
and checked the directory of cwd using os.getcwd()
The directory that I see is /opt/sublimetext
I even tried changing the "cwd" from "cwd": "$file_path", to the current path,"cwd": "/home/sam/desktop/programs/" in the "Main.sublime-menu" file
I was wondering if there is a way that I could register the directory manually or even better if sublimeREPL would automatically pick the directory, since I'll be importing files from different locations.
Thanks.

Resources