【问题标题】:Import a folder as package in python在python中将文件夹作为包导入
【发布时间】:2019-03-01 17:10:11
【问题描述】:

我用的是linux服务器,但是我没有权限用pip安装包,所以我从https://github.com/blue-yonder/tsfresh下载了我需要的包:tsfresh,然后用ftp上传解压的包我下载到Linux服务器的文件夹,但是我怎么import tsfresh??

我把下载文件夹放在路径/upload/tsfresh,我的python工作目录在/upload/

以下是我的文件夹upload的子文件夹

./tsfresh
./tsfresh/.github
./tsfresh/binder
./tsfresh/docs
./tsfresh/notebooks
./tsfresh/tests
./tsfresh/tsfresh
./tsfresh/docs/api
./tsfresh/docs/images
./tsfresh/docs/text
./tsfresh/docs/_static
./tsfresh/docs/_templates
./tsfresh/tests/integrations
./tsfresh/tests/units
./tsfresh/tests/integrations/examples
./tsfresh/tests/units/feature_extraction
./tsfresh/tests/units/feature_selection
./tsfresh/tests/units/scripts
./tsfresh/tests/units/transformers
./tsfresh/tests/units/utilities
./tsfresh/tsfresh/convenience
./tsfresh/tsfresh/examples
./tsfresh/tsfresh/feature_extraction
./tsfresh/tsfresh/feature_selection
./tsfresh/tsfresh/scripts
./tsfresh/tsfresh/transformers
./tsfresh/tsfresh/utilities

我的问题是:如何将tsfresh 作为普通包导入。

【问题讨论】:

  • 安装软件包不需要管理员权限。您可以使用“pip install --user tsfresh”为当前用户安装它们
  • 但是pip 还没有安装,我没有安装它的管理员权限。
  • 您也不需要管理员权限来安装 pip。 pip.pypa.io/en/stable/installingcurl https://bootstrap.pypa.io/get-pip.py -o get-pip.pypython get-pip.py --user
  • 我没有权限将文件保存或写入系统,我是只读用户。

标签: python linux package


【解决方案1】:

它在您的项目文件夹中,对吗?那么

import tsfresh

如果它有一个 init.py 使其成为一个模块,它将起作用。

如果它不在该文件夹中,请将其附加到 sys.path

或者让您的管理员安装它。

【讨论】:

  • 使用import tsfresh可以正常使用,但是当我尝试使用这个包的功能例如tsfresh.feature_extraction时,会出现错误:Traceback (most recent call last): File "<stdin>", line 1, in <module> AttributeError: module 'tsfresh' has no attribute 'feature_extraction'
  • init.py吗?
  • 我导入了git文件夹的子tsfresh文件夹,里面有init.py文件,但是还是不能使用这个包的功能。 >>> from tsfresh import extract_features Traceback (most recent call last): File "<stdin>", line 1, in <module> ImportError: cannot import name 'extract_features'
  • 安装依赖包后它可以工作,但是它必须设置一个依赖项才能工作,所以.....这是另一个死胡同............
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2013-12-07
  • 1970-01-01
  • 1970-01-01
  • 2018-12-17
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多