0

I'm trying to access functions from a helper script in the main script but import keeps throwing errors. Both scripts are in the same folder but I can't import one into another like I usually do. Could it be because I'm using a virtual environment this time? How to resolve it?

I've tried:

import crypto
crypto.encrypt() 

but it throws an Attribute Error module 'crypto' has no attribute 'encrypt'

and when I do:

from crypto import encrypt 

it throws ImportError: cannot import name 'encrypt' from 'crypto' (C:\Users\nano\virtual\crypto.py)

I've also tried modifying my launch.json file but it didn't help. What am I doing wrong?

EDIT: it seems to work normally the other way around.

GrozniV
  • 13
  • 3
  • Are you sure the correct version of crypto is installed in your venv and that the venv is activated? – nigh_anxiety Sep 05 '22 at 15:34
  • I'm not trying to access the crypto package, rather my own helper script named crypto.py – GrozniV Sep 07 '22 at 13:53
  • Ok then, a few things to consider then. 1) Is the crypto package also installed in your venv? 2) Is your personal crypto.py script in the correct location that you are importing from without any additional path info? 3) Is your script on its own or is it also part of a package you created also named crypto? See https://stackoverflow.com/questions/24477478/importing-a-python-package-from-a-script-with-the-same-name – nigh_anxiety Sep 07 '22 at 14:28

1 Answers1

1

You seem to have misunderstood the use of this package. First of all, the module encrypt() described in the question does not exist in this package.

enter image description here

The method of using this package is written below:

Encryption (crypto)

$ crypto <options> [file path] <file path 2...>
$ crypto <options> [directory path] <directory path 2...>

Decryption (decrypto)

$ decrypto <options> [file path] <file path 2...>
$ decrypto <options> [directory path] <directory path 2...>

Other methods are also described in detail in docs.

Added:

enter image description here

enter image description here

This works on my vscode.

MingJie-MSFT
  • 5,569
  • 1
  • 2
  • 13
  • It's not the crypto package I'm trying to access but my own helper script named crypto.py – GrozniV Sep 07 '22 at 13:52
  • @GrozniV Please supplement some of your code to reproduce the problem, which runs correctly in my vscode, and I have supplemented it in my answer – MingJie-MSFT Sep 08 '22 at 01:25