Python dependency on Gnome Builder - python

I am learning how to create GTK applications in python and I am using Gnome Builder IDE installed through flatpak.
I wanted to use the python package requests in my application, so I added:
{
"name": "pip-install",
"buildsystem": "simple",
"build-options": {
"build-args": [
"--share=network"
]
},
"build-commands": [
"pip3 install requests"
]
}
To my modules list inside the flatpak .json file of the project.
When I try to build the project I get the following error when the command runs pip:
ERROR: Could not install packages due to an EnvironmentError: [Errno 30] Read-only file system: '/usr/lib/python3.7/site-packages/idna-2.9.dist-info'
One solution would be the dependency being installed on user space, but how to do that?

I've successfully used this snippet before:
{
"name": "requests",
"buildsystem": "simple",
"build-options": {
"build-args": [
"--share=network"
]
},
"build-commands": [
"pip3 install --prefix=/app --no-cache-dir requests"
]
}
The /app directory is writable and the rest of your application should be there as well.

Related

I have installed all the python libraries i want to use in the vscode terminal but when i call to import, it won't work

[{
"resource": "/d:/Users/Home/Desktop/Python/estudos/pratices.py",
"owner": "_generated_diagnostic_collection_name_#0",
"code": {
"value": "reportMissingModuleSource",
"target": {
"$mid": 1,
"external": "https://github.com/microsoft/pyright/blob/main/docs/configuration.md#reportMissingModuleSource",
"path": "/microsoft/pyright/blob/main/docs/configuration.md",
"scheme": "https",
"authority": "github.com",
"fragment": "reportMissingModuleSource"
}
},
"severity": 4,
"message": "Import \"pandas\" could not be resolved from source",
"source": "Pylance",
"startLineNumber": 1,
"startColumn": 8,
"endLineNumber": 1,
"endColumn": 14
}]
is the message given
the cmd shell tells me i have all the libraries i want installed and they're in the project folder, i'm running a virtual environment but whenever i try to run something in a .py file, it says that it's not defined, i have installed anaconda but don't mean to use it right now, if i open a jupyter file it'll import no problem, but trying to run pip doesn't work at all
reinstalling vscode, making sure python's installed, making sure pip is installed
I had a similar issue before and the solution I found is that you have to make sure the python interpreter for the current VSC window is your virtual environment instead of the system-wide python interpreter. On windows:
Press F1
Search for "interpreter".
Click the python one
Click "Enter interpreter path".
Finally locate your virtual environment.
You should make sure that the current interpreter and the pandas library installed are the same interpreter environment.
The current interpreter can be output with the following code.
import sys
print(sys.executable)
Then install the pandas library with the resulting interpreter path.
<the path obtained above> -m pip install pandas

Pylance gives a "Import numpy could not be resolved" error when importing packages even though it was previously able to import them

For whatever reason, Pylance has started to refuse to recognize libraries such as numpy and tcod, even though running the command "pip list" shows that I have installed them on my machine.
This problem began happening two days ago, even though it was fine the day before that.
The error message reads, "Import x could not be resolved Pylance(reportMissingImports)"
Running the command "python -m site" returns the following information:
sys.path = [
'/home/username',
'/usr/lib64/python38.zip',
'/usr/lib64/python3.8',
'/usr/lib64/python3.8/lib-dynload',
'/home/username/.local/lib/python3.8/site-packages',
'/usr/lib64/python3.8/site-packages',
'/usr/lib/python3.8/site-packages',
]
USER_BASE: '/home/username/.local' (exists)
USER_SITE: '/home/username/.local/lib/python3.8/site-packages' (exists)
The problem happens in all of my vscode workspaces.
This is what my settings file in my current workspace looks like:
{
"python.autoComplete.extraPaths": [
"/usr/lib64/python3.8/site-packages",
"/home/username/workspace/python",
"/home/username/.var/app/com.visualstudio.code/data/python/lib/python3.9/site-packages",
"/username/bin/python3.8",
"/home/username",
"/usr/lib64/python38.zip",
"/usr/lib64/python3.8",
"/usr/lib64/python3.8/lib-dynload",
"/home/username/.local/lib/python3.8/site-packages",
"/usr/lib64/python3.8/site-packages",
"/usr/lib/python3.8/site-packages",
"/usr/local/lib64/python3.8/site-packages",
"/var/data/python/bin"
],
"python.defaultInterpreterPath": "/home/python38/python",
"python.analysis.extraPaths": [
"/sur/lib64/python3.8/site-packages",
"/home/username/workspace/python",
"/home/username/.var/app/com.visualstudio.code/data/python/lib/python3.9/site-packages",
"/username/bin/python3.8",
"/home/username",
"/usr/lib64/python38.zip",
"/usr/lib64/python3.8",
"/usr/lib64/python3.8/lib-dynload",
"/home/username/.local/lib/python3.8/site-packages",
"/usr/lib64/python3.8/site-packages",
"/usr/lib/python3.8/site-packages",
"/usr/local/lib64/python3.8/site-packages",
"/var/data/python/bin"
]
}
Here's my current workspace file:
{
"folders": [
{
"path": "."
}
],
"settings": {}
}
Aside from the interpreter available at the default interpreter path, VSCode offers the the following available interpreters:
Python 3.9.7 (Recommended), located at /bin/python
Python 3.9.7, located at /sbin/python
Python 3.9.7, located at /usr/bin/python
Python 3.9.7, located at /usr/sbin/python
I've tried all of them as well as the entry for "python.defaultInterpreterPath" with no luck.

python vscode ImportError: No module named simplejson

i have import simplejson in my code, and installed using pip install simplejson using python3
so as i checked, it perfectly runs in my terminal opening the file but when i try to build in VScode, it shows an error like,
see the error in this link as
`> Executing task: python /Users/Tony/Documents/python3.9/helloworld.py <
Traceback (most recent call last):
File "/Users/Tony/Documents/python3.9/helloworld.py", line 1, in
import simplejson as json
ImportError: No module named simplejson
The terminal process "/bin/bash '-c', 'python /Users/Tony/Documents/python3.9/helloworld.py'" failed to launch (exit code: 1).
but it still runs on my terminal. and if i check the pip list, simplejson is still there and i also tried to use different version of python too.
and I have activated the virtual environment enter image description here
and i am using the last one which i recently activated.
please help me to find the error. i don’t really know where to fix thanks
I've reproduced this process and hope the following steps could help you
1.Activate the venv and install simplejson;
2.Run the helloworld.py in Terminal to make sure the script no error;
3.Configure the tasks.json, pay attention to use the venv's pythonpath;
"version": "2.0.0",
"tasks": [
{
"label": "run python file",
"type": "shell",
"command": "/venv's pythonpath/ helloworld.py",
"group": {
"kind": "test",
"isDefault": true
},
"problemMatcher": [
"$tsc"
]
}
]
4.Tasks:Run Task;

Setuptools entry_points/console_scripts have specific Python version in shebang

I am generating a Python package on RHEL6 (with Python2.6), and trying to deploy it to a RHEL7 server (Python2.7). The package includes scripts generated with entry_points/console_scripts.
However, the generated scripts have the specific python2.6 version in the shebang, as in:
#!/usr/bin/env python2.6
How can I override or disable this so it just generates:
#!/usr/bin/env python
entry_points = {
'console_scripts':[
...
]
},
options = {
'build_scripts': {
'executable': '/usr/bin/env python',
},
},

Esky not including sub-module

I have a medium-size PyQT5 desktop application that has been working fine with py2app. I want to incorporate Esky so that the app can update itself, but the app terminates during startup (before displaying the main window) with a log entry that says "HelloApp Error" (where "HelloApp" is the name of my application).
I've created a small test case that reproduces the problem that is available at https://github.com/markmont/esky-package-question
The test-case app has the following structure:
HelloApp/
HelloApp/
HelloApp.py
helloform
__init__.py
setup.py
setup.py contains:
from esky import bdist_esky
from distutils.core import setup
PY2APP_OPTIONS = {
'argv_emulation': True,
'includes': [ 'sip', 'PyQt5', 'helloform' ],
'qt_plugins': [ '*' ]
}
ESKY_OPTIONS = {
"freezer_module": "py2app",
"freezer_options": PY2APP_OPTIONS,
"includes": [ 'sip', 'PyQt5', 'helloform' ]
}
HelloApp = bdist_esky.Executable( "HelloApp/HelloApp.py", gui_only=True )
setup(
name='HelloApp',
version = "2014060301",
data_files=[],
options = { "bdist_esky": ESKY_OPTIONS },
scripts=[ HelloApp ]
)
HelloApp.py contains the statement from helloform import Form -- this appears to be what is causing the app to fail to start with the error "HelloApp Error", as if I remove that statement and paste in the contents of helloform/init.py the application starts up and works properly.
Also, if I move everything into a single directory and adjust the paths in setup.py, then the problem does not occur -- Esky finds helloform.py (formerly named helloform/init.py), includes it, and the application starts up and works properly:
HelloApp/
HelloApp.py
helloform.py # formerly ./HelloApp/helloform/__init__.py
setup.py
...but putting everything in single directory is not a scalable solution for a medium-to-large application.
There are no error messages in the output of python setup.py bdist_esky when the problem occurs, and I have not found the answer in the Esky documentation or in various examples on the web.
The full error from /var/log/system.log is:
2014-06-03 13:03:07.100 HelloApp[14968]: HelloApp Error
I'm assuming that I'm not using Esky's includes option properly in setup.py, but I've got no clue as to how to fix this -- can anyone help?
Other possibly relevant details: MacOS X 10.9 Mavericks, Python 2.7.6 (local build), qt-5.3.0 opensource, sip 4.16, PyQT 5.3.0 (GPL), py2app 0.8.1 patched to support PyQT5, and the latest version of Esky from GitHub.
Thanks in advance!
I've solved this problem -- the problem was due to my limited knowledge of Python distutils and setuptools. Since things "just worked" with py2app (which was using setuptools), I assumed that the problem was with how Etsy was configured when the problem was really with how I was using distutils.
The problem was that helloworld.py was not being copied into the frozen app.
The solution involved restructuring the files and changing the disutils configuration to explicitly add HelloApp as a package.
New file structure:
HelloApp/
hello.py # formerly HelloApp.py
HelloApp/
__init__.py
helloform.py
setup.py
New setup.cfg:
from esky import bdist_esky
from distutils.core import setup
PY2APP_OPTIONS = {
'argv_emulation': True,
'includes': [ 'sip', 'PyQt5' ],
'qt_plugins': [ '*' ]
}
ESKY_OPTIONS = {
"freezer_module": "py2app",
"freezer_options": PY2APP_OPTIONS,
"includes": [ 'sip', 'PyQt5' ]
}
HelloApp = bdist_esky.Executable( "hello.py", gui_only=True )
setup(
name='hello',
version = "2014060301",
data_files=[],
options = { "bdist_esky": ESKY_OPTIONS },
scripts=[ HelloApp ],
packages=[ 'HelloApp' ],
)

Categories

Resources