Python Trouble Importing Local Package Inside Local Package
up vote
1
down vote
favorite
this is my first post on here and I'm also fairly new to python, for the past two days I've been struggling with the error:
Traceback (most recent call last):
File "Main.py", line 6, in <module>
import PyScrape
File "/Users/arya/Desktop/Coding/Python/ROBLOX/[ROBLOX] Account Creation Bot/PyScrape/__init__.py", line 1, in <module>
from . import ProxyScraper
File "/Users/arya/Desktop/Coding/Python/ROBLOX/[ROBLOX] Account Creation Bot/PyScrape/ProxyScraper/__init__.py", line 6, in <module>
from . import FreeProxyList
ModuleNotFoundError: No module named 'ProxyScraper'
when trying to import the "ProxyScraper" directory in the __init__.py
file within the "PyScrape" directory, my file structure is below, let me know if I need to disclose more information.
PyScrape/
__init__.py
ProxyChecker.py
ProxyScraper/
__init__.py
CheckerProxy.py
FreeProxyList.py
Hidester.py
HttpTunnel.py
PremProxy.py
SpysMe.py
Utility.py
The contents of the __init__.py
within the "PyScrape" directory is the following:
from . import ProxyScraper
from . import ProxyChecker
def Scrape():
return ProxyChecker.CheckProxyList(ProxyScraper.Scrape())
The contents of the __init__.py
within the "ProxyScraper" directory is as follows:
from threading import Thread
from queue import Queue
from . import FreeProxyList
from . import Hidester
from . import CheckerProxy
from . import SpysMe
from . import HttpTunnel
SourceArray = ["FreeProxyList", "Hidester", "CheckerProxy", "SpysMe", "HttpTunnel"]
def Scrape():
WorkerList =
ProxyQueue = Queue()
for Source in SourceArray:
Worker = Thread(name=Source, target=eval(Source + ".Scrape"), args=(ProxyQueue,))
WorkerList.append(Worker)
Worker.start()
for Worker in WorkerList:
Worker.join()
return ProxyQueue
python python-3.x python-import python-module python-packaging
|
show 9 more comments
up vote
1
down vote
favorite
this is my first post on here and I'm also fairly new to python, for the past two days I've been struggling with the error:
Traceback (most recent call last):
File "Main.py", line 6, in <module>
import PyScrape
File "/Users/arya/Desktop/Coding/Python/ROBLOX/[ROBLOX] Account Creation Bot/PyScrape/__init__.py", line 1, in <module>
from . import ProxyScraper
File "/Users/arya/Desktop/Coding/Python/ROBLOX/[ROBLOX] Account Creation Bot/PyScrape/ProxyScraper/__init__.py", line 6, in <module>
from . import FreeProxyList
ModuleNotFoundError: No module named 'ProxyScraper'
when trying to import the "ProxyScraper" directory in the __init__.py
file within the "PyScrape" directory, my file structure is below, let me know if I need to disclose more information.
PyScrape/
__init__.py
ProxyChecker.py
ProxyScraper/
__init__.py
CheckerProxy.py
FreeProxyList.py
Hidester.py
HttpTunnel.py
PremProxy.py
SpysMe.py
Utility.py
The contents of the __init__.py
within the "PyScrape" directory is the following:
from . import ProxyScraper
from . import ProxyChecker
def Scrape():
return ProxyChecker.CheckProxyList(ProxyScraper.Scrape())
The contents of the __init__.py
within the "ProxyScraper" directory is as follows:
from threading import Thread
from queue import Queue
from . import FreeProxyList
from . import Hidester
from . import CheckerProxy
from . import SpysMe
from . import HttpTunnel
SourceArray = ["FreeProxyList", "Hidester", "CheckerProxy", "SpysMe", "HttpTunnel"]
def Scrape():
WorkerList =
ProxyQueue = Queue()
for Source in SourceArray:
Worker = Thread(name=Source, target=eval(Source + ".Scrape"), args=(ProxyQueue,))
WorkerList.append(Worker)
Worker.start()
for Worker in WorkerList:
Worker.join()
return ProxyQueue
python python-3.x python-import python-module python-packaging
Is ProxyScrapper.py the name of the directory?
– yorodm
Nov 7 at 20:02
@yorodm It's not, that was a typo, I should've read my post over before posting 😖
– Arya
Nov 7 at 23:57
Which__init__.py
are you trying to import your package in? Also could you show us the contents of said__init__.py
?
– Hevlastka
Nov 8 at 0:56
Could you please post the import statement you are using along with the complete error message?
– raratiru
Nov 8 at 1:01
@raratirufrom . import ProxyScraper
– Arya
Nov 8 at 2:34
|
show 9 more comments
up vote
1
down vote
favorite
up vote
1
down vote
favorite
this is my first post on here and I'm also fairly new to python, for the past two days I've been struggling with the error:
Traceback (most recent call last):
File "Main.py", line 6, in <module>
import PyScrape
File "/Users/arya/Desktop/Coding/Python/ROBLOX/[ROBLOX] Account Creation Bot/PyScrape/__init__.py", line 1, in <module>
from . import ProxyScraper
File "/Users/arya/Desktop/Coding/Python/ROBLOX/[ROBLOX] Account Creation Bot/PyScrape/ProxyScraper/__init__.py", line 6, in <module>
from . import FreeProxyList
ModuleNotFoundError: No module named 'ProxyScraper'
when trying to import the "ProxyScraper" directory in the __init__.py
file within the "PyScrape" directory, my file structure is below, let me know if I need to disclose more information.
PyScrape/
__init__.py
ProxyChecker.py
ProxyScraper/
__init__.py
CheckerProxy.py
FreeProxyList.py
Hidester.py
HttpTunnel.py
PremProxy.py
SpysMe.py
Utility.py
The contents of the __init__.py
within the "PyScrape" directory is the following:
from . import ProxyScraper
from . import ProxyChecker
def Scrape():
return ProxyChecker.CheckProxyList(ProxyScraper.Scrape())
The contents of the __init__.py
within the "ProxyScraper" directory is as follows:
from threading import Thread
from queue import Queue
from . import FreeProxyList
from . import Hidester
from . import CheckerProxy
from . import SpysMe
from . import HttpTunnel
SourceArray = ["FreeProxyList", "Hidester", "CheckerProxy", "SpysMe", "HttpTunnel"]
def Scrape():
WorkerList =
ProxyQueue = Queue()
for Source in SourceArray:
Worker = Thread(name=Source, target=eval(Source + ".Scrape"), args=(ProxyQueue,))
WorkerList.append(Worker)
Worker.start()
for Worker in WorkerList:
Worker.join()
return ProxyQueue
python python-3.x python-import python-module python-packaging
this is my first post on here and I'm also fairly new to python, for the past two days I've been struggling with the error:
Traceback (most recent call last):
File "Main.py", line 6, in <module>
import PyScrape
File "/Users/arya/Desktop/Coding/Python/ROBLOX/[ROBLOX] Account Creation Bot/PyScrape/__init__.py", line 1, in <module>
from . import ProxyScraper
File "/Users/arya/Desktop/Coding/Python/ROBLOX/[ROBLOX] Account Creation Bot/PyScrape/ProxyScraper/__init__.py", line 6, in <module>
from . import FreeProxyList
ModuleNotFoundError: No module named 'ProxyScraper'
when trying to import the "ProxyScraper" directory in the __init__.py
file within the "PyScrape" directory, my file structure is below, let me know if I need to disclose more information.
PyScrape/
__init__.py
ProxyChecker.py
ProxyScraper/
__init__.py
CheckerProxy.py
FreeProxyList.py
Hidester.py
HttpTunnel.py
PremProxy.py
SpysMe.py
Utility.py
The contents of the __init__.py
within the "PyScrape" directory is the following:
from . import ProxyScraper
from . import ProxyChecker
def Scrape():
return ProxyChecker.CheckProxyList(ProxyScraper.Scrape())
The contents of the __init__.py
within the "ProxyScraper" directory is as follows:
from threading import Thread
from queue import Queue
from . import FreeProxyList
from . import Hidester
from . import CheckerProxy
from . import SpysMe
from . import HttpTunnel
SourceArray = ["FreeProxyList", "Hidester", "CheckerProxy", "SpysMe", "HttpTunnel"]
def Scrape():
WorkerList =
ProxyQueue = Queue()
for Source in SourceArray:
Worker = Thread(name=Source, target=eval(Source + ".Scrape"), args=(ProxyQueue,))
WorkerList.append(Worker)
Worker.start()
for Worker in WorkerList:
Worker.join()
return ProxyQueue
python python-3.x python-import python-module python-packaging
python python-3.x python-import python-module python-packaging
edited Nov 8 at 13:44
asked Nov 7 at 17:58
Arya
135
135
Is ProxyScrapper.py the name of the directory?
– yorodm
Nov 7 at 20:02
@yorodm It's not, that was a typo, I should've read my post over before posting 😖
– Arya
Nov 7 at 23:57
Which__init__.py
are you trying to import your package in? Also could you show us the contents of said__init__.py
?
– Hevlastka
Nov 8 at 0:56
Could you please post the import statement you are using along with the complete error message?
– raratiru
Nov 8 at 1:01
@raratirufrom . import ProxyScraper
– Arya
Nov 8 at 2:34
|
show 9 more comments
Is ProxyScrapper.py the name of the directory?
– yorodm
Nov 7 at 20:02
@yorodm It's not, that was a typo, I should've read my post over before posting 😖
– Arya
Nov 7 at 23:57
Which__init__.py
are you trying to import your package in? Also could you show us the contents of said__init__.py
?
– Hevlastka
Nov 8 at 0:56
Could you please post the import statement you are using along with the complete error message?
– raratiru
Nov 8 at 1:01
@raratirufrom . import ProxyScraper
– Arya
Nov 8 at 2:34
Is ProxyScrapper.py the name of the directory?
– yorodm
Nov 7 at 20:02
Is ProxyScrapper.py the name of the directory?
– yorodm
Nov 7 at 20:02
@yorodm It's not, that was a typo, I should've read my post over before posting 😖
– Arya
Nov 7 at 23:57
@yorodm It's not, that was a typo, I should've read my post over before posting 😖
– Arya
Nov 7 at 23:57
Which
__init__.py
are you trying to import your package in? Also could you show us the contents of said __init__.py
?– Hevlastka
Nov 8 at 0:56
Which
__init__.py
are you trying to import your package in? Also could you show us the contents of said __init__.py
?– Hevlastka
Nov 8 at 0:56
Could you please post the import statement you are using along with the complete error message?
– raratiru
Nov 8 at 1:01
Could you please post the import statement you are using along with the complete error message?
– raratiru
Nov 8 at 1:01
@raratiru
from . import ProxyScraper
– Arya
Nov 8 at 2:34
@raratiru
from . import ProxyScraper
– Arya
Nov 8 at 2:34
|
show 9 more comments
1 Answer
1
active
oldest
votes
up vote
0
down vote
accepted
For a python module to be imported, its containing directory must be set either in a PYTHONPATH
variable in $HOME/.bashrc
file for example, or explicitly inserted in sys.path
during runtime.
One solution would be:
>>> import sys
>>> sys.path.insert(0, '/path/to/PyScrape')
Another would be:
$ echo 'export PYTHONPATH=$PYTHONPATH:/path/to/PyScrape' >> $HOME/.bashrc
$ source $HOME/.bashrc
Bear in mind that instead of .bashrc
the relevant file could be .profile
.
When you set PYTHONPATH
then the result of the command:
>>> import sys
>>> sys.path
will contain the path you set in $PYTHONPATH
because:
sys.path
is a list of strings that specifies the search path for modules. Initialized from the environment variable PYTHONPATH, plus an installation-dependent default.
how am I able to import the PyScrape directory without adding it to sys.path then, or does this only apply to when importing a package from a subfolder inside a folder being imported?
– Arya
Nov 9 at 23:26
I did mark your answer as the correct one as it did fix the situation, but there must surely be a cleaner way of doing this
– Arya
Nov 10 at 2:05
@Arya By adding the directory to the enviroment variablePYTHONPATH
, it is actually added tosys.path
. As the linked documentation ofsys.path
mentions: "A list of strings that specifies the search path for modules. Initialized from the environment variable PYTHONPATH, plus an installation-dependent default."
– raratiru
Nov 10 at 2:14
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53195114%2fpython-trouble-importing-local-package-inside-local-package%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
accepted
For a python module to be imported, its containing directory must be set either in a PYTHONPATH
variable in $HOME/.bashrc
file for example, or explicitly inserted in sys.path
during runtime.
One solution would be:
>>> import sys
>>> sys.path.insert(0, '/path/to/PyScrape')
Another would be:
$ echo 'export PYTHONPATH=$PYTHONPATH:/path/to/PyScrape' >> $HOME/.bashrc
$ source $HOME/.bashrc
Bear in mind that instead of .bashrc
the relevant file could be .profile
.
When you set PYTHONPATH
then the result of the command:
>>> import sys
>>> sys.path
will contain the path you set in $PYTHONPATH
because:
sys.path
is a list of strings that specifies the search path for modules. Initialized from the environment variable PYTHONPATH, plus an installation-dependent default.
how am I able to import the PyScrape directory without adding it to sys.path then, or does this only apply to when importing a package from a subfolder inside a folder being imported?
– Arya
Nov 9 at 23:26
I did mark your answer as the correct one as it did fix the situation, but there must surely be a cleaner way of doing this
– Arya
Nov 10 at 2:05
@Arya By adding the directory to the enviroment variablePYTHONPATH
, it is actually added tosys.path
. As the linked documentation ofsys.path
mentions: "A list of strings that specifies the search path for modules. Initialized from the environment variable PYTHONPATH, plus an installation-dependent default."
– raratiru
Nov 10 at 2:14
add a comment |
up vote
0
down vote
accepted
For a python module to be imported, its containing directory must be set either in a PYTHONPATH
variable in $HOME/.bashrc
file for example, or explicitly inserted in sys.path
during runtime.
One solution would be:
>>> import sys
>>> sys.path.insert(0, '/path/to/PyScrape')
Another would be:
$ echo 'export PYTHONPATH=$PYTHONPATH:/path/to/PyScrape' >> $HOME/.bashrc
$ source $HOME/.bashrc
Bear in mind that instead of .bashrc
the relevant file could be .profile
.
When you set PYTHONPATH
then the result of the command:
>>> import sys
>>> sys.path
will contain the path you set in $PYTHONPATH
because:
sys.path
is a list of strings that specifies the search path for modules. Initialized from the environment variable PYTHONPATH, plus an installation-dependent default.
how am I able to import the PyScrape directory without adding it to sys.path then, or does this only apply to when importing a package from a subfolder inside a folder being imported?
– Arya
Nov 9 at 23:26
I did mark your answer as the correct one as it did fix the situation, but there must surely be a cleaner way of doing this
– Arya
Nov 10 at 2:05
@Arya By adding the directory to the enviroment variablePYTHONPATH
, it is actually added tosys.path
. As the linked documentation ofsys.path
mentions: "A list of strings that specifies the search path for modules. Initialized from the environment variable PYTHONPATH, plus an installation-dependent default."
– raratiru
Nov 10 at 2:14
add a comment |
up vote
0
down vote
accepted
up vote
0
down vote
accepted
For a python module to be imported, its containing directory must be set either in a PYTHONPATH
variable in $HOME/.bashrc
file for example, or explicitly inserted in sys.path
during runtime.
One solution would be:
>>> import sys
>>> sys.path.insert(0, '/path/to/PyScrape')
Another would be:
$ echo 'export PYTHONPATH=$PYTHONPATH:/path/to/PyScrape' >> $HOME/.bashrc
$ source $HOME/.bashrc
Bear in mind that instead of .bashrc
the relevant file could be .profile
.
When you set PYTHONPATH
then the result of the command:
>>> import sys
>>> sys.path
will contain the path you set in $PYTHONPATH
because:
sys.path
is a list of strings that specifies the search path for modules. Initialized from the environment variable PYTHONPATH, plus an installation-dependent default.
For a python module to be imported, its containing directory must be set either in a PYTHONPATH
variable in $HOME/.bashrc
file for example, or explicitly inserted in sys.path
during runtime.
One solution would be:
>>> import sys
>>> sys.path.insert(0, '/path/to/PyScrape')
Another would be:
$ echo 'export PYTHONPATH=$PYTHONPATH:/path/to/PyScrape' >> $HOME/.bashrc
$ source $HOME/.bashrc
Bear in mind that instead of .bashrc
the relevant file could be .profile
.
When you set PYTHONPATH
then the result of the command:
>>> import sys
>>> sys.path
will contain the path you set in $PYTHONPATH
because:
sys.path
is a list of strings that specifies the search path for modules. Initialized from the environment variable PYTHONPATH, plus an installation-dependent default.
edited Nov 10 at 2:18
answered Nov 9 at 13:11
raratiru
2,90322153
2,90322153
how am I able to import the PyScrape directory without adding it to sys.path then, or does this only apply to when importing a package from a subfolder inside a folder being imported?
– Arya
Nov 9 at 23:26
I did mark your answer as the correct one as it did fix the situation, but there must surely be a cleaner way of doing this
– Arya
Nov 10 at 2:05
@Arya By adding the directory to the enviroment variablePYTHONPATH
, it is actually added tosys.path
. As the linked documentation ofsys.path
mentions: "A list of strings that specifies the search path for modules. Initialized from the environment variable PYTHONPATH, plus an installation-dependent default."
– raratiru
Nov 10 at 2:14
add a comment |
how am I able to import the PyScrape directory without adding it to sys.path then, or does this only apply to when importing a package from a subfolder inside a folder being imported?
– Arya
Nov 9 at 23:26
I did mark your answer as the correct one as it did fix the situation, but there must surely be a cleaner way of doing this
– Arya
Nov 10 at 2:05
@Arya By adding the directory to the enviroment variablePYTHONPATH
, it is actually added tosys.path
. As the linked documentation ofsys.path
mentions: "A list of strings that specifies the search path for modules. Initialized from the environment variable PYTHONPATH, plus an installation-dependent default."
– raratiru
Nov 10 at 2:14
how am I able to import the PyScrape directory without adding it to sys.path then, or does this only apply to when importing a package from a subfolder inside a folder being imported?
– Arya
Nov 9 at 23:26
how am I able to import the PyScrape directory without adding it to sys.path then, or does this only apply to when importing a package from a subfolder inside a folder being imported?
– Arya
Nov 9 at 23:26
I did mark your answer as the correct one as it did fix the situation, but there must surely be a cleaner way of doing this
– Arya
Nov 10 at 2:05
I did mark your answer as the correct one as it did fix the situation, but there must surely be a cleaner way of doing this
– Arya
Nov 10 at 2:05
@Arya By adding the directory to the enviroment variable
PYTHONPATH
, it is actually added to sys.path
. As the linked documentation of sys.path
mentions: "A list of strings that specifies the search path for modules. Initialized from the environment variable PYTHONPATH, plus an installation-dependent default."– raratiru
Nov 10 at 2:14
@Arya By adding the directory to the enviroment variable
PYTHONPATH
, it is actually added to sys.path
. As the linked documentation of sys.path
mentions: "A list of strings that specifies the search path for modules. Initialized from the environment variable PYTHONPATH, plus an installation-dependent default."– raratiru
Nov 10 at 2:14
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53195114%2fpython-trouble-importing-local-package-inside-local-package%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Is ProxyScrapper.py the name of the directory?
– yorodm
Nov 7 at 20:02
@yorodm It's not, that was a typo, I should've read my post over before posting 😖
– Arya
Nov 7 at 23:57
Which
__init__.py
are you trying to import your package in? Also could you show us the contents of said__init__.py
?– Hevlastka
Nov 8 at 0:56
Could you please post the import statement you are using along with the complete error message?
– raratiru
Nov 8 at 1:01
@raratiru
from . import ProxyScraper
– Arya
Nov 8 at 2:34