it works when I run it not compiled but when it's a exe file it gives me the wrong path. something like this:
C:\Users\User\AppData\Local\Temp\_MEI36682\base_library.zip\os.pyc\file.zip
pyinstaller flags:
py -m PyInstaller -F .\downloader.py
It saved the zip file in the correct path but the current_path is wrong so it cant find it
import wget
import zipfile
import os
url = 'https://example.com/file.zip'
filename = wget.download(url)
current_path = str(os.path.dirname(os.path.abspath(__file__)))
path =current_path+'\\'+filename
print(path)
try:
with zipfile.ZipFile(path, 'r') as zip_ref:
zip_ref.extractall(current_path)
except Exception as e:
print(e)
os.startfile(current_path+'\\main.exe')
Related
I have a file file.txt with filenames ending with *.sha256, including the full paths of each file. This is a toy example:
file.txt:
/path/a/9b/x3.sha256
/path/7c/7j/y2.vcf.gz.sha256
/path/e/g/7z.sha256
Each line has a different path/file. The *.sha256 files have checksums.
I want to run the command "sha256sum -c" on each of these *.sha256 files and write the output to an output_file.txt. However, this command only accepts the name of the .sha256 file, not the name including its full path. I have tried the following:
while read in; do
sha256sum -c "$in" >> output_file.txt
done < file.txt
but I get:
"sha256sum: WARNING: 1 listed file could not be read"
which is due to the path included in the command.
Any suggestion is welcome
#!/bin/bash
while read in
do
thedir=$(dirname "$in")
thefile=$(basename "$in")
cd "$thedir"
sha256sum -c "$thefile" >>output_file.txt
done < file.txt
Modify your code to extract the directory and file parts of your in variable.
I'm very new to Nix. I'd like to refer to project scripts in my shell.nix file, so that when I cd into my project directory I can refer to them by name, and I can keep them up-to-date whenever the sources change.
To learn how to do this, I created a very simple derivation for a shell script. Eventually I'd like to use other languages, but I'm starting simple. It looks like this:
project
nix
myScript
default.nix
builder.sh
shell.nix
# default.nix
{ pkgs ? import <nixpkgs> {} }:
pkgs.stdenv.mkDerivation rec {
name = "myScript";
echo = pkgs.coreutils + "/bin/echo";
builder = "${pkgs.coreutils}/bin/bash";
args = [ ./builder.sh ];
}
# builder.sh
$echo "$echo Hello world" > $out
When I run nix-build myScript.nix it creates a symlinked result file that looks like this:
/nix/store/3mfkgajns47hfv0diihzi2scwl4hm2fl-coreutils-9.1/bin/echo Hello world
I tried referencing this in my shell.nix file like this:
{ pkgs ? import (fetchTarball "https://github.com/NixOS/nixpkgs/archive/bf972dc380f36a3bf83db052380e55f0eaa7dcb6.tar.gz") {} }:
let
myScript = import ./myScript {};
in
pkgs.mkShell {
buildInputs = [
myScript
];
shellHook = ''
echo Loading shell.nix
'';
}
But whenever I enter the projects directory and run the command `myScript, I get an error:
zsh: command not found: myScript
I already have direnv configured correctly, which I can confirm by adding other shell tools and checking their versions. So it's something wrong with my nix files.
I'm almost certainly doing something wrong here. I know I can simplify this with pkgs.writeShellScriptBin, but the shell script is more a minimal example of what I want to get working. Eventually I'd use more complex derivations.
What I think is wrong
I think the myScript derivation or builder is doing something wrong. It does create the expected output file (i.e. I can chmod +x and run it, and it works) but I suspect I need to tell nix how to run it? I'm not sure. And also I might be importing the derivation incorrectly.
This is a problem with your default.nix, not your shell.nix.
For mkShell to work with buildInputs as you intend, you need $out to be a directory with an $out/bin/myScript, not a file on its own. nixpkgs has a helper that will do this for you, in https://github.com/NixOS/nixpkgs/blob/master/pkgs/build-support/trivial-builders.nix --
# default.nix; no builder.sh needed
{ pkgs ? import <nixpkgs> {} }:
pkgs.writeShellScript "myScript" ''
echo "Hello world" # use the bash-builtin echo, not the external coreutils one
'';
I'm trying to use nix-shell with a shell.nix file to get a clean development environment but I don't know how to change the location of the temporary build directories.
The buildInputs packages are built in /tmp but this path doesn't have enough space and I get an error: [Errno 28] No space left on device during the build.
I tried running nix-shell with a modified TMPDIR environment variable but it only affects the location of the nix-shell temporary files. The nix-build files are still put in /tmp.
I also tried to export a new value for TMPDIR in the shellHook but it doesn't work.
How can I change the TMPDIR of nix-build when it's started by nix-shell?
Here's my shell.nix:
let
pkgs = import <nixpkgs> {};
in
pkgs.mkShell {
name = "something";
buildInputs = with pkgs; [
python38
python38Packages.pytorchWithCuda
];
shellHook = ''
'';
}
I got the answer on the NixOS forum:
If this is a mutli-user install, you need to modify the Nix daemon’s TMPDIR.
To do that on my system I created a /etc/systemd/system/nix-daemon.service.d/override.conf with:
[Service]
Environment=TMPDIR=/var/tmp/nix-daemon
enter image description here
root#f083f367b874:/app# vim test.py
root#f083f367b874:/app# python test.py
Traceback (most recent call last):
File "test.py", line 13, in
run(playwright)
File "test.py", line 3, in run
browser = playwright.chromium.launch(headless=False)
File "/usr/local/lib/python3.7/site-packages/playwright/sync_api/_generated.py", line 9449, in launch
firefoxUserPrefs=mapping.to_impl(firefox_user_prefs),
File "/usr/local/lib/python3.7/site-packages/playwright/_impl/_sync_base.py", line 103, in _sync
return task.result()
File "/usr/local/lib/python3.7/site-packages/playwright/_impl/_browser_type.py", line 90, in launch
raise e
File "/usr/local/lib/python3.7/site-packages/playwright/_impl/_browser_type.py", line 86, in launch
return from_channel(await self._channel.send("launch", params))
File "/usr/local/lib/python3.7/site-packages/playwright/_impl/_connection.py", line 36, in send
return await self.inner_send(method, params, False)
File "/usr/local/lib/python3.7/site-packages/playwright/_impl/_connection.py", line 54, in inner_send
result = next(iter(done)).result()
playwright._impl._api_types.Error: Host system is missing dependencies!
Missing libraries are:
libnss3.so
libnssutil3.so
libsmime3.so
libnspr4.so
libatk-1.0.so.0
libatk-bridge-2.0.so.0
libcups.so.2
libdrm.so.2
libdbus-1.so.3
libxkbcommon.so.0
libXcomposite.so.1
libXdamage.so.1
libXfixes.so.3
libXrandr.so.2
libgbm.so.1
libasound.so.2
libatspi.so.0
libxshmfence.so.1
How to solve this problem??
If you're using Playwright for Python, run: playwright install-deps
If you're using vanilla JS Playwright, run: npx playwright install-deps
Looks like you're using the Python version.
Try appending
# { pkgs ? import <nixpkgs> {} }:
with import <nixpkgs> {};
stdenv.mkDerivation {
name = "kubelt";
nativeBuildInputs = [ pkg-config ];
buildInputs = [
clojure
clojure-lsp
babashka
leiningen
nodejs-16_x
jdk
docker
google-chrome
chromedriver
act
docker
rustup
libuuid
act
wayland
google-chrome-dev
firefox-bin
]
APPEND_LIBRARY_PATH = "${lib.makeLibraryPath [ libGL libuuid wayland google-chrome-dev firefox-bin]}";
shellHook = ''
LD=$CC
export LD_LIBRARY_PATH="$APPEND_LIBRARY_PATH:$LD_LIBRARY_PATH"
'';
}
I added a custom logger to the waf build command as seen below. The output of this wscript is shown below.
But I want to have the normal waf logger to print on the terminal, and the normal + custom logger output to be written to the log file. Is this possible? The problem is, that the normal output is most times sufficient, and the added verbosity by the custom logger slows down the build quite a lot.
#!/usr/bin/env python
# -*- encoding: utf-8 -*-
top = '.'
out = 'build'
VERSION = '0.0.0'
APPNAME = 'app'
from waflib import Configure, Logs
import logging
Configure.autoconfig = True
def options(opt):
opt.load('compiler_c')
def configure(conf):
conf.load('compiler_c')
conf.path.make_node('main.c').write(
'#include <stdio.h>\n\nint main(int argc, char* argv[]) {\n return 0;\n}\n')
def build(bld):
import sys
import os
log_file = os.path.join(out, 'build.log')
bld.logger = Logs.make_logger(log_file, out)
hdlr = logging.StreamHandler(sys.stdout)
formatter = logging.Formatter('%(message)s')
hdlr.setFormatter(formatter)
bld.logger.addHandler(hdlr)
bld.program(target='app', source='main.c')
The produced output is like this:
$ python waf
Configuring the project
Setting top to : /cygdrive/d/log
Setting out to : /cygdrive/d/log/build
Checking for 'gcc' (C compiler) : /usr/bin/gcc
Waf: Entering directory `/cygdrive/d/log/build'
[1/2] Compiling main.c
['/usr/bin/gcc', '../main.c', '-c', '-o/cygdrive/d/log/build/main.c.1.o']
[2/2] Linking build/app.exe
['/usr/bin/gcc', '-Wl,--enable-auto-import', 'main.c.1.o', '-o/cygdrive/d/log/build/app.exe', '-Wl,-Bstatic', '-Wl,-Bdynamic']
Waf: Leaving directory `/cygdrive/d/log/build'
'build' finished successfully (0.473s)
What I need is a terminal output like this:
[1/2] Compiling main.c
[2/2] Linking build/app.exe
and a log file output like this:
[1/2] Compiling [32mmain.c[0m
['/usr/bin/gcc', '../main.c', '-c', '-o/cygdrive/d/log/build/main.c.1.o']
[2/2] Linking [33mbuild/app.exe[0m
['/usr/bin/gcc', '-Wl,--enable-auto-import', 'main.c.1.o', '-o/cygdrive/d/log/build/app.exe', '-Wl,-Bstatic', '-Wl,-Bdynamic']
Bonus: How can the non printable characters be removed only in the log file output?