-2

File senha:

def seu_token():
      return'your token pass'

File main:

import discord
import random
from senha import seu_token

PROBLEM: When I use the from import or import the importation doesn't occur. I tested and found that all the imports I make from a file that I made have this problem. If I try to import from another file/lib/API, it works normally.

ALREADY TRY: All type of import, Create a New Project only to test the imports and really doesn't work. Re-install PyCharm, Re-code files, ask on Groups for Help and until now, no solution.

Masoud Rahimi
  • 5,785
  • 15
  • 39
  • 67
Bruno R.
  • 1
  • 1
  • 1
    Can you also show the directory tree of your project (where the files are located relative to one another), and whether you have a file called `__init__.py` or not? – Mihai Chelaru Apr 26 '19 at 12:39
  • does the senha.py file is in the root directory of the project or in a separate package? – Nipun Thennakoon Apr 26 '19 at 12:39
  • @MihaiChelaru The files are in the same directory C:(...)\Python\BOTv2\Main\Vital. I do not have a file called __init__.py, i used python a year ago, basically I rewrite the codes and used the same way for the imports. – Bruno R. Apr 26 '19 at 13:05
  • What do you mean by "*the importation doesn't occur*"? Do you get any error? Also, did you try `from .senha import seu_token`? – CristiFati Apr 26 '19 at 13:13
  • Yes i tried @CristiFati. And I think that I found accidentally the answer. The directory wasn't in Source Root, I'm testing and I will post the answer soon. Thanks anyway. – Bruno R. Apr 26 '19 at 13:30
  • https://stackoverflow.com/questions/54955891/how-pycharm-imports-differently-than-system-command-prompt-windows/55083046#55083046? – CristiFati Apr 26 '19 at 13:32

1 Answers1

0

When you create a new project in PyCharm You are working by default in a virtual environment that just have the basic python packages.

Just open the terminal in PyCharm and install the packages you need via pip/pip3.Don't worry, if you have them installed in your computer you will fetch the packages from the cache automatically.

Or just exit the virtual environment by typing in the Pycharm terminal as deactivate and you will be able to use the local packages.

Gonzalo Garcia
  • 6,192
  • 2
  • 29
  • 32