I'm trying to compile a .sol with py-solc-x.
I downloaded the library with pip install py-solc-x but still, vscode doesn't recognize it.
please help me fix this.
The massage after pip install
The code
You create virtual environment and then install it. I get alot of imports error in pycahrm and vscode for packages.
python3 -m venv venv
source venv/bin/activate
pip3 install py-solc-x
Also the way you import package is not correct. this is how you should setp:
from solcx import compile_standard, install_solc
# whichever version u want to use
install_solc("0.8.0")
You have installed the solcx in the global python310 environment, please check which python interpreter you have selected from the bottom-left on the VSCode.
I'm working on the same tutorial and ran into the same issue as you. I followed #Steven-MSFT's tip and got the code to work. Take a look:
from solcx import compile_standard, install_solc
_solc_version = "0.6.0"
install_solc(_solc_version)
with open("./SimpleStorage.sol", "r") as file:
simple_storage_file = file.read()
# Compile our solidity
compiled_sol = compile_standard(
{
"language": "Solidity",
"sources": {"SimpleStorage.sol": {"content": simple_storage_file}},
"settings": {
"outputSelection": {
"*": {"*": ["metadata", "evm.bytecode", "evm.sourceMap"]}
}
},
},
solc_version=_solc_version,
)
print(compiled_sol)
Then I ran python3 deploy.py and it successfully outputted the ABI JSON object!
I also founded this issue. The problem is Python is install globally but site package is in user appdata, in your case "C:\users\kin...\python310\site-packages".
i had uninstalled python and deleted python310 folder in user appdata then installed python and packages again, this time in vscode python extnsion setting page tick "Global module installation".
i hope this work for you too.
Related
I have a python library in github I want to debug. The library has setup.py as well as a pip released package. So I can install this module using either pip install git-sim or python3 setup.py install.
This module adds a command to the path and I can execute in terminal with git-sim .
Main Problem: I want to clone the github repo and open vscode inside the cloned repo and debug the code getting executed while I am running the command from the terminal. The breakpoints should hit the file inside the repo.
Link to the github Repo: https://github.com/initialcommit-com/git-sim
I went searching with these requirements. Best I could come up so far is
An edit mode in setup.py which can be started by pip install -e . . While I ran this command and was successful I did not see a way to debug it.
How do we debug a module in Vscode? Give this code in launch.json
{
"name": "Python: Module",
"type": "python",
"request": "launch",
"module": "git-sim",
"justMyCode": false,
}
But while I am running this I am getting an error, no module named git-sim even though the same command works outside the debugger in the terminal. i.e both git-sim and python3 -m git_sim
Any suggestion of where I maybe going wrong? Or if there is some alternative option I have not considered
Found the issue. I made a mistake in assuming the terminal command git-sim and the actual python -m git_sim were same.
Module Name and Terminal commands are different. So if we modify launch config from "module":"git-sim" to "module":"git_sim" it works. Modified config given below:
{
"name": "Python: Module",
"type": "python",
"request": "launch",
"module": "git_sim",
"justMyCode": false,
}
Here is the code
from solcx import compile_standard, install_solc
import json
with open("./SimpleStorage.sol", "r") as file:
simple_storage_file = file.read()
install_solc("0.6.0")
compiled_sol = compile_standard(
{
"language": "Solidity",
"sources": {"SimpleStorage.sol": {"content": simple_storage_file}},
"settings": {
"outputSelection": {
"*": {"*": ["abi", "metadata", "evm.bytecode", "evm.sourceMap"]}
}
},
},
solc_version="0.6.0",
)
with open("compiled_code.json", "w") as file:
json.dump(compiled_sol, file)
In the terminal, I have ran the commands of: pip3 install py-solc-x and pip install solc and get a response that the requirement is already satisfied separately for both commands.
I also get the error of INFO: Could not find files for the given pattern(s). when I run the command of python deploy.py
This is how by VS Code folder looks like on my Local Disk:
the python source file and SOL file are in the same folder
As you can probably tell, I am very new as I'm taking freeCodeCamps beginners course. Any and all help is great appreciated, thank you in advance.
This is for resolving the first error:
Exit from any virtual environments by running "deactivate" (or "conda deactivate" for exiting from an Anaconda virtual environment).
Run python3 from the terminal
Run these lines of code as follows:
import solcx
solcx.install_solc() #or you can install a specific version by running "solcx.install_solc('0.6.0')"(without the quotes) or any other version in the brackets.
As for the second error, check if the SimpleStorage.sol file is present in the same directory as the given python code file. And also the "compiled_code.json" file will automatically be created in the same folder as that of the given python file(due to the "w" argument present in the open function).
Could you check where you have installed the modules? pip3 show py-solc-x.
And check which python interpreter you have selected from the bottom-left on the VSCode:
You can click it to select the python interpreter or reinstall the modules in the environment you have selected.
And from your image, it's a little weird about your filename. Your file was named SimpleStorage.sol while another file was named deploy and its type was Python Source File. So you look like have hidden the filename extension, so your file name needs to be SimpleStorage.
import solcx
solcx.install_solc("0.6.0")
this worked for me
i have been trying to access my firebase DB through a python program on my rapberry pi 3, but i have been encountering the same import error
File "/home/pi/Desktop/testFB.py", line 1, in <module>
import pyrebase
ImportError: No module named 'pyrebase'
Here is the code
import pyrebase
config = {
"apiKey": "apikey",
"authDomain": "db.firebaseapp.com",
"databaseURL": "https://db.firebaseio.com/",
"storageBucket": "db.appspot.com"
}
firebase = Pyrebase.initialize_app(config)
db=firebase.database()
print(db.get())
upon running 'pip3 list', 'Pyrebase==3.0.27' is in there
but in the file /usr/lib/python3.5 (where the rest of my modules are) Pyrebase.py is not there?
any help is appreciated, although similar questions have solutions that have not been working for me...
thanks in advance,
3NiGMa
You have either not installed the module or the path where the module is installed is not included in your current python PATH.
I recommend to use pip to install all modules.
pip install pyrebase
You can show your include paths with:
python -c "import sys; print('\n'.join(sys.path))"
Can you find your pyrebase folder in those paths? If not something is wrong with your config.
I also recommend that you use virtualenv, for more information see https://docs.python-guide.org/dev/virtualenvs/ as you can choose python interpreter version and depedencies for every project and you don't have to mix modules needed by other projects. It also always creates a clean state for a new project.
Rolling back uninstall of pycryptodome
Moving to c:\users\hitman\appdata\local\programs\python\python38-32\lib\site-packages\crypto
from C:\Users\Hitman\AppData\Local\Programs\Python\Python38-32\Lib\site-packages~rypto
Moving to c:\users\hitman\appdata\local\programs\python\python38-32\lib\site-packages\pycryptodome-3.9.8.dist-info
from C:\Users\Hitman\AppData\Local\Programs\Python\Python38-32\Lib\site-packages~ycryptodome-3.9.8.dist-info
I want to run Pylint or any equivalent while using Jupyter-Notebook. Is there a way to install and run Pylint this way?
pycodestyle is an equivalent of pylint for Jupyter Notebook which is able to check your code against the PEP8 style guide.
First, you need to install the pycodestyle in jupyter notebook by typing this command,
!pip install pycodestyle pycodestyle_magic
Run this command in a cell of jupyter notebook.
After successful installation, you have to load the magic in a Jupyter Notebook cell like this,
%load_ext pycodestyle_magic
Then, you have to use pycodestyle in a cell in which you want to investigate your code against PEP8 standards.
Below are some examples for more and clear understanding,
%%pycodestyle
a=1
Output: pycodestyle will give you this message,
2:2: E225 missing whitespace around operator
Another example,
%%pycodestyle
def square_of_number(
num1, num2, num3,
num4):
return num1**2, num2**2, num3**2, num4**2
Output:
2:1: E302 expected 2 blank lines, found 0
3:23: W291 trailing whitespace
I suggest you consider the nbQA tool:
pip install nbqa pylint
nbqa pylint my_notebook.ipynb
Besides pylint, nbqa makes it easy to run several other formatter and linter tools and is easy to integrate into your development workflow via their dedicated pre-commit hooks.
To answer the question more specifically in regards to pylint. One relatively simple way to achieve that in a development / ci environment (i.e. command line) is to convert the notebook to Python and then run the linting.
Let's assume you have notebooks in the ./notebooks folder and you have the jupyter and pylint command in the path, you could run the following:
jupyter nbconvert \
--to=script \
--output-dir=/tmp/converted-notebooks/ \
./notebooks/*.ipynb
pylint /tmp/converted-notebooks/*.py
You might want to configure pylint, as the notebook style is slightly different to a general Python module.
Some rules that you might want to disable:
pointless-statement
expression-not-assigned
trailing-newlines
wrong-import-position
redefined-outer-name
invalid-name
It also appears that the maximum number of characters in a cell (before horizontal scrolling) is 116 but that might depend on other factors.
(These options can for example be configured using the --max-line-length and --disable pylint arguments, or via the .pylintrc file)
The JupyterLab extension jupyterlab-lsp supports pylint (but pylint is disabled by default):
https://github.com/python-lsp/python-lsp-server/issues/171#event-6236223765
pip install jupyterlab-lsp
pip install 'python-lsp-server[all]'
Here is my config for the LanguageServer tab under Settings => Advanced Settings Editor, enabling pylint:
{
"language_servers": {
"pyright": {
"serverSettings": {
"python.analysis.useLibraryCodeForTypes": true
}
},
"pylsp": {
"serverSettings": {
"pylsp": {
"plugins": {
"pydocstyle": {
"enabled": true
},
"pyflakes": {
"enabled": false
},
"flake8": {
"enabled": true
},
"pylint": {
"enabled": true
}
}
}
}
}
}
}
In case you opt for using nbqa but you happen to have notebooks using pyspark as framework (instead of python), the following command will fail to recognize your notebooks:
nbqa pylint **/*.ipynb
The reason is that .ipynb files using pyspark have this metadata in the body:
"metadata": {
"name": "pyspark"
}
which prevents nbqa for recognizing it as python type. The solution is to simply substitute the value of "pyspark" with "python", here is a shell script that does it (you might need to install jq):
for i in $(find . -type f -name "*.ipynb");
do jq '.metadata.language_info.name="python"' "$i" > "$i".ipynb;
nbqa pylint "$i".ipynb -f colorized --fail-under=7;
rm "$i".ipynb;
done;
I am trying to build and distribute rpm package of python module for centos. I have followed following steps
created virtualenv and installed requires
in module added setup.py with install_requires.
then using python2.7 from virtualenv build package
../env/bin/python2.7 setup.py bdist_rpm
Now I got src, no-arch and tar-gz files in 'dist' folder.
foo-0.1-1.noarch.rpm, foo-0.1-1.src.rpm, foo-0.1.tar.gz
I tried to install package src-rpm using 'sudo yum install foo-0.1-1.src.rpm',
got error something like wrong architecture
Then I tried to install package no-arch, 'sudo yum install foo-0.1-1.noarch.rpm' it works smoothly.
But after running script, it gave some import error. here I expect to download that module automatically.
The last thing is I am using some third party library which is not on pip.
So I want to whole setup using virtualenv with required modules. So after installing rpm, user can run script directly instead of installing third party libs separately and explicitly.
Some above steps may sounds wrong, as I am new to this stuff.
Following is code in setup.py
from setuptools import setup, find_packages
setup(
name = "foo",
version = "0.1",
packages = find_packages(),
scripts = ['foo/bar.py', ],
# Project uses reStructuredText, so ensure that the docutils get
# installed or upgraded on the target machine
install_requires = ['PyYAML', 'pyOpenSSL', 'pycrypto', 'privatelib1,'privatelib2', 'zope.interface'],
package_data = {
# If any package contains *.txt or *.rst files, include them:
'': ['*.txt', '*.rst'],
# And include any *.msg files found in the 'billing' package, too:
'foo': ['*.msg'],
},
# metadata for upload to PyPI
author = "foo bar",
description = "foo bar",
license = "",
keywords = "foo bar",
# could also include long_description, download_url, classifiers, etc.
)
Also I am using shebang in script as,
#!/usr/bin/env python2.7
Note:
I have multiple python setups. 2.6 and 2.7
By default 'python' commands gives 2.6
while command 'python2.7' gives python2.7
output of `'rpm -qp foo-0.1-1.noarch.rpm --requires' =>
`/usr/bin/python
python(abi) = 2.6
rpmlib(CompressedFileNames) <= 3.0.4-1
rpmlib(PayloadFilesHavePrefix) <= 4.0-1
When i install pakcage. script's shebang line (which is now '/usr/bin/bar.py') is getting changed to /usr/bin/python' But I exclusively want to run script on python2.7.
Thanks in advance