Import Error while importing test module in VScode - pytest

In my VScode I have the attached image folder structure and when I am trying to run any test it says Import error while importing test module enter image description here
I my settings.json file I have
"terminal.intergarted.env.windows":{PYTHONPATH": "${workspaceFolder}/src"},
"python.envFile": "${workspaceFolder}/.env",
Can anyhelp help what I can do to make my test module import , It seems right now its not able to find the test folder itself .

Related

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

Project doesnt run when i change folder name in lib folder

i changed folder name to mian_screen and then when i run it gives error and cant find the path any more as you see in image.image of error
You can change the way you are importing things.
Instead of doing import '../models/orders.dart
Try import 'package:firstproject/models/orders.dart

Pylint Error: Attempted relative import beyond top-level package

Here in VSCode whenever I write the following line from . import dispatcher pylint always gives error statement saying Attempted relative import beyond top-level package.
But when I run the module using this command: python -m src.train the program runs without flashing any error. Here is the screenshot from the VSCode editor:
Does someone know who to solve this thing in VSCode?
Just add an empty __init__.py file of the folder that contains your dispatcher.py file, then all the .py files under the folder, as whole, should be recognized as a package. And the lint error should dismiss.

ImportError: when importing from a local script library

Does importing from a local script lib work in qpython3?
I have a script I created in the Qpython projects3 directory of qpython.
projects3/MPU6502/
I have my main code here in this directory.
main.py
I have a local subdirectory,
projects3/MPU6502/tiny6502lib/
In this sub directory I have the source code,
RAM_8bit_Memory.py
From my main.py source code I load the library,
#-*-coding:utf8;-*-
#qpy:3
#qpy:console
# import 6502 library module
from tiny6502lib.RAM_8bit_Memory import *
when I execute the library import I get the ERRORL:
"ImportError: No module named tiny6502lib.RAM_8bit_Memory"
Is importing local script libraries broken in qpython3?
org.qpython.py/projects/MPU6502/main.py
org.qpython.py/projects/MPU6502/tiny6502lib/RAM_8bit_Memory.py
This code works perfectly on all other flavors of python3 (windows) and pythonista on ipad.
How do I get this import to work? Or does it not work at all?
thank you,
Just try to insert the following code before importing tiny6502lib.RAM_8bit_Memory
import sys
sys.path.append("/sdcard/qpython/projects3/MPU6502")
?

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.