not found utils/context.sol when i import from openzepplin - importerror

i have copied a contract from openzappline. but when i compile it on remix it gives me the error....that utils/context.sol is not found.
here is the import
pragma solidity ^0.8.0;
import "./IERC20.sol";
import "./extensions/IERC20Metadata.sol";
import "../../utils/Context.sol";
contract ERC20 is Context, IERC20, IERC20Metadata {
mapping (address => uint256) private _balances;
mapping (address => mapping (address => uint256)) private _allowances;
uint256 private _totalSupply;
string private _name;
string private _symbol;

import "#openzeppelin/contracts/utils/Context.sol";
this should help
The file that's being called is from the root directory, not inside the ERC20 files.

import "../../utils/Context.sol";
This line tries to import the file Context.sol from "utils" folder located "two folders up" relative to the folder where your ERC20 contract is located.
Easiest solution in this context (where no other contract imports the Context.sol) is to copy-paste the Context.sol to a reachable location (e.g. to the same folder as your ERC20) and change the import path (e.g. to import "./Context.sol").

If youre importing an openzeppelin contract ex:
import "#openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
make sure to include a GPL-3 licence
// SPDX-License-Identifier: GPL-3.0
this helped me to get the npm deps in remix

Related

ModuleNotFoundError:No module name 'odoo.addons,base.res'

I got above error when I try to run the next code
from odoo import models, fields, api
from odoo.exceptions import ValidationError
from odoo.addons.base.res.res_request import referenceable_models
Because there is no res name module present in base module thats why it is giving an error

How to import .py in google Colaboratory?

I want to simplify code. so i make a utils.py , but Google Colaboratory directory is "/content" I read other questions. but this is not my solution
In Google's Colab notebook, How do I call a function from a Python file?
%%writefile example.py
def f():
print 'This is a function defined in a Python source file.'
# Bring the file into the local Python environment.
execfile('example.py')
f()
This is a function defined in a Python source file.
It look likes just using def().
using this, i always write the code in cell.
but i want to this code
import example.py
example.f()
A sample maybe you want:
!wget https://raw.githubusercontent.com/tensorflow/models/master/samples/core/get_started/iris_data.py -P local_modules -nc
import sys
sys.path.append('local_modules')
import iris_data
iris_data.load_data()
I have also had this problem recently.
I addressed the issue by the following steps, though it's not a perfect solution.
src = list(files.upload().values())[0]
open('util.py','wb').write(src)
import util
This code should work with Python 3:
from google.colab import drive
import importlib.util
# Mount your drive. It will be at this path: "/content/gdrive/My Drive/"
drive.mount('/content/gdrive')
# Load your module
spec = importlib.util.spec_from_file_location("YOUR_MODULE_NAME", "/content/gdrive/My Drive/utils.py")
your_module_name = importlib.util.module_from_spec(spec)
spec.loader.exec_module(your_module_name)
import importlib.util
import sys
from google.colab import drive
drive.mount('/content/gdrive')
# To add a directory with your code into a list of directories
# which will be searched for packages
sys.path.append('/content/gdrive/My Drive/Colab Notebooks')
import example.py
This works for me.
Use this if you are out of content folder! hope this help!
import sys
sys.path.insert(0,'/content/my_project')
from example import*
STEP 1. I have just created a folder 'common_module' like shown in the image :
STEP 2 called the required Class from my "colab" code cell,
sys.path.append('/content/common_module/')
from DataPreProcessHelper import DataPreProcessHelper as DPPHelper
My class file 'DataPreProcessHelper.py' looks like this
Add path of 'sample.py' file to system paths as:
import sys
sys.path.append('drive/codes/')
import sample

Postgres PL/JAVA: java.lang.ClassNotFoundException error after loading JAR file in database

I am getting the java.lang.ClassNotFoundException: error inside Postgres when running a function that calls a JAR file I have loaded. I have installed and configured PL/JAVA (including the delivered examples) in my database and can run the examples to success. I am not attempting to load/install my first JAR, but I am doing something wrong.
My host controls the OS version: CentOS 6.8. Postgres is version 8.4.
I am attempting to install my own very simple java class, which is a derivative of the delivered example Parameters.addOne class. All my code is in /tmp. Here are the steps I've followed:
Doug.java:
package com.msmetric;
import java.math.BigDecimal;
import java.sql.Date;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Time;
import java.sql.Timestamp;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.TimeZone;
import java.util.logging.Logger;
public class Doug {
public static int addOne(int value) {
return value + 1;
}
}
Compile Doug.java using 'javac Doug.java' succeeds.
Create JAR file with Doug.class file in it using 'jar -cvf Doug.jar Doug.class. This works fine.
Now I load the JAR file into Postgres (public schema), change the classpath, create the function that calls the JAR, then attempt to run at psql prompt.
Run sqlj.install_jar from psql:
select sqlj.install_jar('file:/tmp/Doug.jar','Doug',false);
Set the classpath inside Postgres (from psql prompt postgres=#):
select sqlj.set_classpath('public','Doug');
Create the function that calls the JAR. This create function code is taken directly from the examples.ddr file that came with PL/JAVA. I simply changed org.postgres to com.msmetric.
create or replace function addone(int) returns int as 'com.msmetric.Doug.addOne(java.lang.Integer)' language java;
Now with the JAR loaded and function created, I attempt to run it. This function should simply add 1 to the number provided.
select addone(3);
Results:
ERROR: java.lang.ClassNotFoundException: com.msmetric.Doug
Thoughts?
I'm very sorry I didn't see your question sooner. Underneath all the exotic details (PostgreSQL, PL/Java, schemas, classpaths...), there's just a bit of basic Java going on here: if a jar file contains a class Doug.class in package com.msmetric, its path within the jar has to reflect that: it has to be com/msmetric/Doug.class. Otherwise, it won't be found.
You can set up that whole structure step by step:
javac Doug.java
mkdir com
mkdir com/msmetric
mv Doug.class com/msmetric/
jar -cvf Doug.jar com/msmetric/Doug.class
Or, you can let javac do more of the work for you:
mkdir classes
javac -d classes Doug.java
jar -cvf Doug.jar -C classes .
When you give javac a -ddirectory option, instead of just writing class files next to their .java sources, it will put them all in their proper places under the directory you named, and then you can just tell jar to change into that directory and slurp them all up (don't overlook the . at the end of that jar command).
Once you fix that, if you retry your original steps, you'll see that you now get a different error:
ERROR: Unable to find static method com.msmetric.Doug.addOne with signature (Ljava/lang/Integer;)I
That happens because you declared the function in Doug.java with int addOne(int value) (that is, taking a primitive int argument), but you declared it in SQL with returns int as 'com.msmetric.Doug.addOne(java.lang.Integer)' taking an Integer object.
Once you correct that:
create or replace function addone(int) returns int as 'com.msmetric.Doug.addOne(int)' language java;
you'll be able to see:
# select addone(3);
addone
--------
4
(1 row)
If you happen to see this belated answer, may I ask what version of PL/Java you are using? That's one detail you didn't mention. If it is older than 1.5.0, there are newer features that can help you out. For one, you can just annotate that function:
#Function
public static int addOne(int value) {
return value + 1;
}
and have javac spit out not only the Doug.class file but also a pljava.ddr file with your SQL function declaration already written correctly (no mixing up argument types!). There is a way to include that .ddr file into the jar you create so that you can just call sqlj.install_jar with the last parameter true so it runs the commands in the .ddr and your functions are ready to use. There's a Hello, world example in the docs that shows more of how it's done.
Cheers,
-Chap

How to extend an ember-cli addon?

In my ember-cli app i have installed an addon called 'ember-cli-selectize'. Looking at the directory structure i can see that its files are located at /node_modules/ember-cli-selectize'. Now i want to create a custom component that extends this addon. How do i import/require it? I've tried these and none seems to work:
var EmberSelectize = require('/ember-cli-selectize/app/components/ember-selectize');
import EmberSelectize from 'components/ember-selectize';
import EmberSelectize from 'node_modules/ember-cli-selectize/addon/components/ember-selectize';
import EmberSelectize from 'ember-cli-selectize/addon/components/ember-selectize';
i always get this 'Could not find module' error no matter what. I need to somehow import/require it to do something like
import EmberSelectize from 'wherever/it/is';
export default EmberSelectize.extend({
//my own customizations
})
You were close with:
import EmberSelectize from 'components/ember-selectize';
Addons namespace themselves - in this case, ember-cli-selectize. So, just add the namespace to your import:
import EmberSelectizeComponent from 'ember-cli-selectize/components/ember-selectize';
then you can extend:
export default EmberSelectizeComponent.extend({ });

alembic/env.py target_metadata = metadata "No module name al_test.models"

When I use alembic to control the version of my project's database,part of codes in env.py
like:
# add your model's MetaData object here
# for 'autogenerate' support
# from myapp import mymodel
# target_metadata = mymodel.Base.metadata
from al_test.models import metadata
target_metadata = metadata
when I run 'alembic revision --autogenerate -m "Added user table"', I get an error :
File "alembic/env.py", line 18, in
from al_test.models import metadata
ImportError: No module named al_test.models
so how to solve the question? thanks!
This might be a bit late, and you may have already figured out the issue, but my guess the problem is that your alembic/ directory is not part of the system path. I.e. you need to do something like:
import sys
sys.path.append(path/to/al_test)
from al_test.models import metadata
Update your env.py like this, to add the current working directory to the sys.path that Python uses when searching for modules:
import os
import sys
sys.path.append(os.getcwd())
from al_test.models import metadata
target_metadata = metadata
....
....