why is importing torchvision showing error the first time while it is getting imported smoothly when importing the second time? - import

Whenever I am importing torchvision, i am getting the error
>>> import torchvision
and the error i receive is
UserWarning: Failed to load image Python extension: Could not find module
'C:\Users\Aditya\anaconda3\Lib\site-packages\torchvision\image.pyd' (or one of its dependencies). Try using the full path with constructor syntax.
warn(f"Failed to load image Python extension: {e}")
but when i import it the second time it gets imported smoothly. I am impporting the facenet_pytorch library which implicitly imports torchvision. This is creating an error while importing facenet_pytorch. What to do next?

Related

QGIS plugin - getting ModuleNotFoundError when importing specifically python-ternary

I am building a QGIS plugin and I'd like to import a module named python-ternary. I have a specific issue importing this module (others get imported), and importing it in QGIS (works outside of QGIS).
I installed it using pip, tried to import it outside of QGIS, works fine.
Now writing this in my plugin main file:
from qgis.PyQt.QtCore import QSettings, QTranslator, QCoreApplication, Qt
from qgis.PyQt.QtGui import QIcon, QColor
from qgis.PyQt.QtWidgets import QAction, QApplication
from .resources import *
import psycopg2
import ternary
I get this when loading my plugin with the QGIS plugin manager:
QGIS error when loading the plugin
Now the python-ternary module is well installed in lib\site-packages:
ternary file in lib\site-packages
And lib\site-packages is on path as shown in the QGIS error.
I have no problem importing other modules in QGIS e.g. psycopg2 is imported without issue. I force reinstalled python-ternary with pip, to no avail.
Is there a compatibility issue with this particular module I'm not aware of ?

install4j how to parse json in a form component

I'm trying to parse json in an action script for a form component.
I tried to:
import javax.json.JsonObject;
And get the following on a test compile:
Failed to compile script
1. ERROR in /private/var/folders/3t/l3dvn7tx1j76wsx17xfjcpww0000gn/T/script10053200329813627000.java.dir/code/Completion.java (at line 1)
import javax.json.JsonObject;
The import javax.json cannot be resolved
How do I achieve the equivalent of this import so I can parse json? I started going down the rabbit hole of create a JMOD for javax.json but that's starting to seem like the wrong path.
The package javax.json is not part of the JRE, but a JEE 7 API. You can download the JAR file from
https://mvnrepository.com/artifact/javax.json/javax.json-api/1.1.4
and add it on the "Installer->Screens & Actions->Custom code" step. Then the class will be available in all scripts.

vscode error when importing from other python files

I set up a virtual env and whenever I try to import from another python file that lives inside the same folder as the one Im importing to I just get this error:
ImportError: cannot import name 'function' from 'f' (c:\Users\catso\Desktop\Network-Scratch\venv\f.py)
what I don't get is the when I go to write the import line it has function there as an option for auto complete so Im not sure why it cant find it?
f file
Import file

H2OConnectionError: Not connected to a cluster

hi guys recently i've encounter this problem in google colab, and i dont know how to solve this problem
import h2o
h2o.init
data_train = "https://drive.google.com/open?id=14OYzA93IkuKPlkdvXs9Od53HyopgSQ2u"
data_train_df = h2o.import_file(path=data_train)
i following a book that suggest these following codes, but somehow it wont work.
The h2o package is not automatically installed in Google Colab. If you attempt to run import h2o without installing it, you will get the following error.
---------------------------------------------------------------------------
ModuleNotFoundError Traceback (most recent call last)
<ipython-input-1-accdebc0c7de> in <module>()
----> 1 import h2o
ModuleNotFoundError: No module named 'h2o'
---------------------------------------------------------------------------
NOTE: If your import is failing due to a missing package, you can
manually install dependencies using either !pip or !apt.
To view examples of installing some common dependencies, click the
"Open Examples" button below.
---------------------------------------------------------------------------
Based on the error message you can then start a new code block and run !pip install h2o to install the package. Then, running import h2o should be successful.
One more thing to keep in mind is that you need to include parentheses to call a function. Running h2o.init will return the description <function h2o.h2o.init>. Try h2o.init() to initialize an h2o cluster.
Edit: The “not connected to a cluster” means you have not initialized a cluster. Try the h2o.init() command again, but using parenthesis so that the function is called and not printed.

How to import libraries in Spark Notebook

I'm having trouble importing magellan-1.0.4-s_2.11 in spark notebook. I've downloaded the jar from https://spark-packages.org/package/harsha2010/magellan and have tried placing SPARK_HOME/bin/spark-shell --packages harsha2010:magellan:1.0.4-s_2.11 in the Start of Customized Settings section of the spark-notebook file of the bin folder.
Here are my imports
import magellan.{Point, Polygon, PolyLine}
import magellan.coord.NAD83
import org.apache.spark.sql.magellan.MagellanContext
import org.apache.spark.sql.magellan.dsl.expressions._
import org.apache.spark.sql.Row
import org.apache.spark.sql.types._
And my errors...
<console>:71: error: object Point is not a member of package org.apache.spark.sql.magellan
import magellan.{Point, Polygon, PolyLine}
^
<console>:72: error: object coord is not a member of package org.apache.spark.sql.magellan
import magellan.coord.NAD83
^
<console>:73: error: object MagellanContext is not a member of package org.apache.spark.sql.magellan
import org.apache.spark.sql.magellan.MagellanContext
I then tried to import the new library like any other library by placing it into the main script like so:
$lib_dir/magellan-1.0.4-s_2.11.jar"
This didn't work and I'm left scratching my head wondering what I've done wrong. How do I import libraries such as magellan into spark notebook?
Try evaluating something like
:dp "harsha2010" % "magellan" % "1.0.4-s_2.11"
It will load the library into Spark, allowing it to be imported - assuming it can be obtained though the Maven repo. In my case it failed with a message:
failed to load 'harsha2010:magellan:jar:1.0.4-s_2.11 (runtime)' from ["Maven2 local (file:/home/dev/.m2/repository/, releases+snapshots) without authentication", "maven-central (http://repo1.maven.org/maven2/, releases+snapshots) without authentication", "spark-packages (http://dl.bintray.com/spark-packages/maven/, releases+snapshots) without authentication", "oss-sonatype (https://oss.sonatype.org/content/repositories/releases/, releases+snapshots) without authentication"] into /tmp/spark-notebook/aether/b2c7d8c5-1f56-4460-ad39-24c4e93a9786
I think file was to big and connection was interrupted before whole file could be downloaded.
Workaround
So I downloaded the JAR manually from:
http://dl.bintray.com/spark-packages/maven/harsha2010/magellan/1.0.4-s_2.11/
and copied it into the:
/tmp/spark-notebook/aether/b2c7d8c5-1f56-4460-ad39-24c4e93a9786/harsha2010/magellan/1.0.4-s_2.11
And then :dp command worked. Try Calling it first, and if it will fail copy JAR into the right path to make things work.
Better solution
I should investigate why download failed to fix it in the first place... or put that library in my local M2 repo. But that should get you going.
I would suggest to check this:
https://github.com/spark-notebook/spark-notebook/blob/master/docs/metadata.md#import-download-dependencies
and
https://github.com/spark-notebook/spark-notebook/blob/master/docs/metadata.md#add-spark-packages
I think the :dp magic command is depreciated, instead you should add your custom dependencies in the notebook metadata. You can go in the menu Edit > Edit notebook metadata, there add something like:
"customDeps": [
"harsha2010 % magellan % 1.0.4-s_2.11"
]
Once done, you will need to restart the kernel, you can check in the browser console if the package is being downloaded properly.
The easy way, you should set or add the EXTRA_CLASSPATH environnent variable to point to your .jar file downloaded :
export EXTRA_CLASSPATH = </link/to/your.jar> or set EXTRA_CLASSPATH= </link/to/your.jar> in wondows OS. Here find the detailed solution.